mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-17 03:16:27 -04:00
Add Butterknife
This commit is contained in:
parent
d3ed56a6ee
commit
db41c6e8b2
@ -76,6 +76,8 @@ import android.widget.ImageView;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -99,18 +101,25 @@ import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback;
|
|||||||
import org.kiwix.kiwixmobile.views.KiwixWebView;
|
import org.kiwix.kiwixmobile.views.KiwixWebView;
|
||||||
|
|
||||||
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
|
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
|
||||||
import static org.kiwix.kiwixmobile.TableDrawerAdapter.*;
|
import static org.kiwix.kiwixmobile.TableDrawerAdapter.DocumentSection;
|
||||||
|
import static org.kiwix.kiwixmobile.TableDrawerAdapter.TableClickListener;
|
||||||
|
|
||||||
public class KiwixMobileActivity extends AppCompatActivity {
|
public class KiwixMobileActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static final String TAG_KIWIX = "kiwix";
|
|
||||||
|
|
||||||
public static final String TAG_FILE_SEARCHED = "searchedarticle";
|
|
||||||
|
|
||||||
public static final int REQUEST_FILE_SEARCH = 1236;
|
public static final int REQUEST_FILE_SEARCH = 1236;
|
||||||
|
|
||||||
public static final int REQUEST_STORAGE_PERMISSION = 1;
|
public static final int REQUEST_STORAGE_PERMISSION = 1;
|
||||||
|
|
||||||
|
private static final int REQUEST_FILE_SELECT = 1234;
|
||||||
|
|
||||||
|
private static final int REQUEST_PREFERENCES = 1235;
|
||||||
|
|
||||||
|
private static final int BOOKMARK_CHOSEN_REQUEST = 1;
|
||||||
|
|
||||||
|
public static final String TAG_KIWIX = "kiwix";
|
||||||
|
|
||||||
|
public static final String TAG_FILE_SEARCHED = "searchedarticle";
|
||||||
|
|
||||||
private static final String TAG_CURRENT_FILE = "currentzimfile";
|
private static final String TAG_CURRENT_FILE = "currentzimfile";
|
||||||
|
|
||||||
private static final String TAG_CURRENT_ARTICLES = "currentarticles";
|
private static final String TAG_CURRENT_ARTICLES = "currentarticles";
|
||||||
@ -135,31 +144,17 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
public static final String PREF_FULL_TEXT_SEARCH = "pref_full_text_search";
|
public static final String PREF_FULL_TEXT_SEARCH = "pref_full_text_search";
|
||||||
|
|
||||||
private static final int REQUEST_FILE_SELECT = 1234;
|
|
||||||
|
|
||||||
private static final int REQUEST_PREFERENCES = 1235;
|
|
||||||
|
|
||||||
private static final int BOOKMARK_CHOSEN_REQUEST = 1;
|
|
||||||
|
|
||||||
public static final String PREF_STORAGE = "pref_selected_storage";
|
public static final String PREF_STORAGE = "pref_selected_storage";
|
||||||
|
|
||||||
public static final String PREF_STORAGE_TITLE = "pref_selected_title";
|
public static final String PREF_STORAGE_TITLE = "pref_selected_title";
|
||||||
|
|
||||||
public static boolean isFullscreenOpened;
|
public static boolean isFullscreenOpened;
|
||||||
|
|
||||||
private static Uri KIWIX_LOCAL_MARKET_URI;
|
private boolean isBackToTopEnabled;
|
||||||
|
|
||||||
private static Uri KIWIX_BROWSER_MARKET_URI;
|
private boolean isSpeaking;
|
||||||
|
|
||||||
private String documentParserJs;
|
private boolean isOpenNewTabInBackground;
|
||||||
|
|
||||||
public Menu menu;
|
|
||||||
|
|
||||||
public Toolbar toolbar;
|
|
||||||
|
|
||||||
public ImageButton exitFullscreenButton;
|
|
||||||
|
|
||||||
public List<TableDrawerAdapter.DocumentSection> documentSections;
|
|
||||||
|
|
||||||
public static boolean nightMode;
|
public static boolean nightMode;
|
||||||
|
|
||||||
@ -171,21 +166,17 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
protected int requestWebReloadOnFinished;
|
protected int requestWebReloadOnFinished;
|
||||||
|
|
||||||
|
private static Uri KIWIX_LOCAL_MARKET_URI;
|
||||||
|
|
||||||
|
private static Uri KIWIX_BROWSER_MARKET_URI;
|
||||||
|
|
||||||
|
private String documentParserJs;
|
||||||
|
|
||||||
private DocumentParser documentParser;
|
private DocumentParser documentParser;
|
||||||
|
|
||||||
private boolean isBackToTopEnabled;
|
public List<TableDrawerAdapter.DocumentSection> documentSections;
|
||||||
|
|
||||||
private boolean isSpeaking;
|
public Menu menu;
|
||||||
|
|
||||||
private boolean isOpenNewTabInBackground;
|
|
||||||
|
|
||||||
private Button backToTopButton;
|
|
||||||
|
|
||||||
private Button pauseTTSButton;
|
|
||||||
|
|
||||||
private LinearLayout TTSControls;
|
|
||||||
|
|
||||||
private DrawerLayout drawerLayout;
|
|
||||||
|
|
||||||
private ArrayList<String> bookmarks;
|
private ArrayList<String> bookmarks;
|
||||||
|
|
||||||
@ -197,23 +188,14 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private TabDrawerAdapter tabDrawerAdapter;
|
private TabDrawerAdapter tabDrawerAdapter;
|
||||||
|
|
||||||
private FrameLayout contentFrame;
|
|
||||||
|
|
||||||
private RelativeLayout toolbarContainer;
|
|
||||||
|
|
||||||
private int currentWebViewIndex = 0;
|
private int currentWebViewIndex = 0;
|
||||||
|
|
||||||
private AnimatedProgressBar progressBar;
|
|
||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
// Initialized when onActionModeStarted is triggered.
|
|
||||||
private ActionMode actionMode = null;
|
private ActionMode actionMode = null;
|
||||||
|
|
||||||
private KiwixWebView tempForUndo;
|
private KiwixWebView tempForUndo;
|
||||||
|
|
||||||
private LinearLayout snackbarLayout;
|
|
||||||
|
|
||||||
private RateAppCounter visitCounterPref;
|
private RateAppCounter visitCounterPref;
|
||||||
|
|
||||||
private int tempVisitCount;
|
private int tempVisitCount;
|
||||||
@ -224,6 +206,43 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private BookmarksDao bookmarksDao;
|
private BookmarksDao bookmarksDao;
|
||||||
|
|
||||||
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
|
|
||||||
|
@BindView(R.id.button_backtotop) Button backToTopButton;
|
||||||
|
|
||||||
|
@BindView(R.id.button_stop_tts) Button stopTTSButton;
|
||||||
|
|
||||||
|
@BindView(R.id.button_pause_tts) Button pauseTTSButton;
|
||||||
|
|
||||||
|
@BindView(R.id.tts_controls) LinearLayout TTSControls;
|
||||||
|
|
||||||
|
@BindView(R.id.toolbar_layout) RelativeLayout toolbarContainer;
|
||||||
|
|
||||||
|
@BindView(R.id.progress_view) AnimatedProgressBar progressBar;
|
||||||
|
|
||||||
|
@BindView(R.id.FullscreenControlButton) ImageButton exitFullscreenButton;
|
||||||
|
|
||||||
|
@BindView(R.id.linearlayout_main) LinearLayout snackbarLayout;
|
||||||
|
|
||||||
|
@BindView(R.id.new_tab_button) RelativeLayout newTabButton;
|
||||||
|
|
||||||
|
@BindView(R.id.drawer_layout) DrawerLayout drawerLayout;
|
||||||
|
|
||||||
|
@BindView(R.id.left_drawer_list) RecyclerView tabDrawerLeft;
|
||||||
|
|
||||||
|
@BindView(R.id.right_drawer_list) RecyclerView tableDrawerRight;
|
||||||
|
|
||||||
|
@BindView(R.id.content_frame) FrameLayout contentFrame;
|
||||||
|
|
||||||
|
@BindView(R.id.action_back_button) ImageView tabBackButton;
|
||||||
|
|
||||||
|
@BindView(R.id.action_forward_button) ImageView tabForwardButton;
|
||||||
|
|
||||||
|
@BindView(R.id.action_back) View tabBackButtonContainer;
|
||||||
|
|
||||||
|
@BindView(R.id.action_forward) View tabForwardButtonContainer;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActionModeStarted(ActionMode mode) {
|
public void onActionModeStarted(ActionMode mode) {
|
||||||
if (actionMode == null) {
|
if (actionMode == null) {
|
||||||
@ -266,8 +285,8 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
handleLocaleCheck();
|
handleLocaleCheck();
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
|
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
||||||
toolbar.setPadding(0, 0, 0, 0);
|
toolbar.setPadding(0, 0, 0, 0);
|
||||||
toolbar.setContentInsetsAbsolute(0, 0);
|
toolbar.setContentInsetsAbsolute(0, 0);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
@ -294,13 +313,6 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
requestInitAllMenuItems = false;
|
requestInitAllMenuItems = false;
|
||||||
isBackToTopEnabled = false;
|
isBackToTopEnabled = false;
|
||||||
isSpeaking = false;
|
isSpeaking = false;
|
||||||
backToTopButton = (Button) findViewById(R.id.button_backtotop);
|
|
||||||
Button stopTTSButton = (Button) findViewById(R.id.button_stop_tts);
|
|
||||||
pauseTTSButton = (Button) findViewById(R.id.button_pause_tts);
|
|
||||||
TTSControls = (LinearLayout) findViewById(R.id.tts_controls);
|
|
||||||
toolbarContainer = (RelativeLayout) findViewById(R.id.toolbar_layout);
|
|
||||||
progressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
|
|
||||||
exitFullscreenButton = (ImageButton) findViewById(R.id.FullscreenControlButton);
|
|
||||||
|
|
||||||
pauseTTSButton.setOnClickListener(new View.OnClickListener() {
|
pauseTTSButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -322,37 +334,30 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
stopTTSButton.setOnClickListener((View view) -> tts.stop());
|
stopTTSButton.setOnClickListener((View view) -> tts.stop());
|
||||||
tempForUndo = new KiwixWebView(getApplicationContext());
|
tempForUndo = new KiwixWebView(getApplicationContext());
|
||||||
snackbarLayout = (LinearLayout) findViewById(R.id.linearlayout_main);
|
|
||||||
|
|
||||||
FileReader fileReader = new FileReader();
|
FileReader fileReader = new FileReader();
|
||||||
documentParserJs = fileReader.readFile("js/documentParser.js", this);
|
documentParserJs = fileReader.readFile("js/documentParser.js", this);
|
||||||
|
|
||||||
RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button);
|
|
||||||
newTabButton.setOnClickListener((View view) -> newTab());
|
newTabButton.setOnClickListener((View view) -> newTab());
|
||||||
RelativeLayout nextButton = (RelativeLayout) findViewById(R.id.action_forward);
|
tabForwardButtonContainer.setOnClickListener((View view) -> {
|
||||||
nextButton.setOnClickListener((View view) -> {
|
|
||||||
if (getCurrentWebView().canGoForward()) {
|
if (getCurrentWebView().canGoForward()) {
|
||||||
getCurrentWebView().goForward();
|
getCurrentWebView().goForward();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RelativeLayout previousButton = (RelativeLayout) findViewById(R.id.action_back);
|
tabBackButtonContainer.setOnClickListener((View view) -> {
|
||||||
previousButton.setOnClickListener((View view) -> {
|
|
||||||
if (getCurrentWebView().canGoBack()) {
|
if (getCurrentWebView().canGoBack()) {
|
||||||
getCurrentWebView().goBack();
|
getCurrentWebView().goBack();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
documentSections = new ArrayList<>();
|
documentSections = new ArrayList<>();
|
||||||
tabDrawerAdapter = new TabDrawerAdapter(mWebViews);
|
tabDrawerAdapter = new TabDrawerAdapter(mWebViews);
|
||||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
||||||
RecyclerView tabDrawerLeft = (RecyclerView) findViewById(R.id.left_drawer_list);
|
|
||||||
tabDrawerLeft.setLayoutManager(new LinearLayoutManager(this));
|
tabDrawerLeft.setLayoutManager(new LinearLayoutManager(this));
|
||||||
tabDrawerLeft.setAdapter(tabDrawerAdapter);
|
tabDrawerLeft.setAdapter(tabDrawerAdapter);
|
||||||
|
tableDrawerRight.setLayoutManager(new LinearLayoutManager(this));
|
||||||
RecyclerView rightDrawerList = (RecyclerView) findViewById(R.id.right_drawer_list);
|
|
||||||
rightDrawerList.setLayoutManager(new LinearLayoutManager(this));
|
|
||||||
|
|
||||||
TableDrawerAdapter tableDrawerAdapter = new TableDrawerAdapter();
|
TableDrawerAdapter tableDrawerAdapter = new TableDrawerAdapter();
|
||||||
rightDrawerList.setAdapter(tableDrawerAdapter);
|
tableDrawerRight.setAdapter(tableDrawerAdapter);
|
||||||
tableDrawerAdapter.setTableClickListener(new TableClickListener() {
|
tableDrawerAdapter.setTableClickListener(new TableClickListener() {
|
||||||
@Override public void onHeaderClick(View view) {
|
@Override public void onHeaderClick(View view) {
|
||||||
getCurrentWebView().setScrollY(0);
|
getCurrentWebView().setScrollY(0);
|
||||||
@ -422,7 +427,6 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
drawerToggle.syncState();
|
drawerToggle.syncState();
|
||||||
|
|
||||||
compatCallback = new CompatFindActionModeCallback(this);
|
compatCallback = new CompatFindActionModeCallback(this);
|
||||||
contentFrame = (FrameLayout) findViewById(R.id.content_frame);
|
|
||||||
setUpTTS();
|
setUpTTS();
|
||||||
documentParser = new DocumentParser(new DocumentParser.SectionsListener() {
|
documentParser = new DocumentParser(new DocumentParser.SectionsListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -1458,12 +1462,10 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refreshNavigationButtons() {
|
public void refreshNavigationButtons() {
|
||||||
ImageView back = (ImageView) findViewById(R.id.action_back_button);
|
toggleImageViewGrayFilter(tabBackButton, getCurrentWebView().canGoBack());
|
||||||
ImageView forward = (ImageView) findViewById(R.id.action_forward_button);
|
toggleImageViewGrayFilter(tabForwardButton, getCurrentWebView().canGoForward());
|
||||||
toggleImageViewGrayFilter(back, getCurrentWebView().canGoBack());
|
tabBackButtonContainer.setEnabled(getCurrentWebView().canGoBack());
|
||||||
toggleImageViewGrayFilter(forward, getCurrentWebView().canGoForward());
|
tabForwardButtonContainer.setEnabled(getCurrentWebView().canGoForward());
|
||||||
findViewById(R.id.action_back).setEnabled(getCurrentWebView().canGoBack());
|
|
||||||
findViewById(R.id.action_forward).setEnabled(getCurrentWebView().canGoForward());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleImageViewGrayFilter(ImageView image, boolean state) {
|
public void toggleImageViewGrayFilter(ImageView image, boolean state) {
|
||||||
@ -1549,7 +1551,6 @@ public class KiwixMobileActivity extends AppCompatActivity {
|
|||||||
editor.putString(TAG_CURRENT_POSITIONS, positions.toString());
|
editor.putString(TAG_CURRENT_POSITIONS, positions.toString());
|
||||||
editor.putInt(TAG_CURRENT_TAB, currentWebViewIndex);
|
editor.putInt(TAG_CURRENT_TAB, currentWebViewIndex);
|
||||||
|
|
||||||
// Commit the edits!
|
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user