mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Merge branch 'master' into search-language-fix
This commit is contained in:
commit
6335d524de
@ -29,6 +29,7 @@ import static android.support.test.espresso.Espresso.onData;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.longClick;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeDown;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
|
||||
@ -103,8 +104,8 @@ public class DownloadTest {
|
||||
allOf(withText("Device"), isDisplayed()));
|
||||
appCompatTextView3.perform(click());
|
||||
|
||||
onView(withId(R.id.menu_rescan_fs))
|
||||
.perform(click());
|
||||
onView(withId(R.id.zim_swiperefresh))
|
||||
.perform(swipeDown());
|
||||
|
||||
/*
|
||||
Commented out the following as it uses another Activity.
|
||||
|
@ -45,6 +45,7 @@ import static android.support.test.espresso.Espresso.openContextualActionModeOve
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.longClick;
|
||||
import static android.support.test.espresso.action.ViewActions.scrollTo;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeDown;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
@ -130,8 +131,8 @@ public class NetworkTest {
|
||||
onView(withText(R.string.local_zims))
|
||||
.perform(click());
|
||||
|
||||
onView(withId(R.id.menu_rescan_fs))
|
||||
.perform(click());
|
||||
onView(withId(R.id.zim_swiperefresh))
|
||||
.perform(swipeDown());
|
||||
|
||||
|
||||
onData(withContent("wikipedia_ab_all_2017-03")).inAdapterView(withId(R.id.zimfilelist)).perform(click());
|
||||
|
@ -1565,6 +1565,19 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuOpened(int featureId, Menu menu) {
|
||||
if (drawerLayout.isDrawerOpen(tabDrawerLeftContainer)) {
|
||||
drawerLayout.closeDrawer(tabDrawerLeftContainer);
|
||||
}
|
||||
|
||||
if (drawerLayout.isDrawerOpen(tableDrawerRightContainer)) {
|
||||
drawerLayout.closeDrawer(tableDrawerRightContainer);
|
||||
}
|
||||
|
||||
return super.onMenuOpened(featureId, menu);
|
||||
}
|
||||
|
||||
// This method refreshes the menu for the bookmark system.
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
|
@ -43,6 +43,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -74,10 +75,13 @@ public class ZimContentProvider extends ContentProvider {
|
||||
|
||||
@Inject public static Context context;
|
||||
|
||||
private static ArrayList<String> listedEntries;
|
||||
|
||||
public void setupDagger() {
|
||||
KiwixApplication.getInstance().getApplicationComponent().inject(this);
|
||||
setIcuDataDirectory();
|
||||
jniSearcher = new JNIKiwixSearcher();
|
||||
listedEntries = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +109,12 @@ public class ZimContentProvider extends ContentProvider {
|
||||
|
||||
public synchronized static String setZimFile(String fileName) {
|
||||
JNIKiwixReader reader = new JNIKiwixReader(fileName);
|
||||
|
||||
if(!listedEntries.contains(reader.getId())) {
|
||||
listedEntries.add(reader.getId());
|
||||
jniSearcher.addKiwixReader(reader);
|
||||
}
|
||||
|
||||
if (!new File(fileName).exists() || reader == null) {
|
||||
Log.e(TAG_KIWIX, "Unable to open the ZIM file " + fileName);
|
||||
zimFileName = null;
|
||||
|
@ -63,8 +63,6 @@ public class ZimManageActivity extends AppCompatActivity {
|
||||
|
||||
public Toolbar toolbar;
|
||||
|
||||
public MenuItem refeshItem;
|
||||
|
||||
private MenuItem searchItem;
|
||||
|
||||
private MenuItem languageItem;
|
||||
@ -129,17 +127,14 @@ public class ZimManageActivity extends AppCompatActivity {
|
||||
return;
|
||||
switch (position) {
|
||||
case 0:
|
||||
refeshItem.setVisible(true);
|
||||
searchItem.setVisible(false);
|
||||
languageItem.setVisible(false);
|
||||
break;
|
||||
case 1:
|
||||
refeshItem.setVisible(false);
|
||||
searchItem.setVisible(true);
|
||||
languageItem.setVisible(true);
|
||||
break;
|
||||
case 2:
|
||||
refeshItem.setVisible(false);
|
||||
searchItem.setVisible(false);
|
||||
languageItem.setVisible(false);
|
||||
break;
|
||||
@ -195,7 +190,6 @@ public class ZimManageActivity extends AppCompatActivity {
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_zim_manager, menu);
|
||||
refeshItem = menu.findItem(R.id.menu_rescan_fs);
|
||||
searchItem = menu.findItem(R.id.action_search);
|
||||
languageItem = menu.findItem(R.id.select_language);
|
||||
searchView = (SearchView) searchItem.getActionView();
|
||||
@ -233,12 +227,6 @@ public class ZimManageActivity extends AppCompatActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_rescan_fs: {
|
||||
if (mViewPager.getCurrentItem() == 0) {
|
||||
ZimFileSelectFragment fragment = (ZimFileSelectFragment) mSectionsPagerAdapter.getItem(0);
|
||||
fragment.refreshFragment();
|
||||
}
|
||||
}
|
||||
case R.id.select_language:
|
||||
if (mViewPager.getCurrentItem() == 1)
|
||||
showLanguageSelect();
|
||||
|
@ -31,6 +31,7 @@ import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -78,11 +79,13 @@ public class ZimFileSelectFragment extends Fragment
|
||||
public static final String TAG_KIWIX = "kiwix";
|
||||
public static ZimManageActivity context;
|
||||
public RelativeLayout llLayout;
|
||||
public SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
private RescanDataAdapter mRescanAdapter;
|
||||
private ArrayList<LibraryNetworkEntity.Book> mFiles;
|
||||
private ListView mZimFileList;
|
||||
private RelativeLayout progressBar;
|
||||
private TextView mFileMessage;
|
||||
private boolean mHasRefresh;
|
||||
|
||||
private BookDao bookDao;
|
||||
|
||||
@ -106,7 +109,18 @@ public class ZimFileSelectFragment extends Fragment
|
||||
mZimFileList = (ListView) llLayout.findViewById(R.id.zimfilelist);
|
||||
|
||||
mFiles = new ArrayList<>();
|
||||
progressBar = (RelativeLayout) super.getActivity().getLayoutInflater().inflate(R.layout.progress_bar, null);
|
||||
|
||||
// SwipeRefreshLayout for the list view
|
||||
swipeRefreshLayout = (SwipeRefreshLayout) llLayout.findViewById(R.id.zim_swiperefresh);
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
refreshFragment();
|
||||
}
|
||||
});
|
||||
|
||||
// A boolean to distinguish between a user refresh and a normal loading
|
||||
mHasRefresh = false;
|
||||
|
||||
mRescanAdapter = new RescanDataAdapter(ZimFileSelectFragment.context, 0, mFiles);
|
||||
|
||||
@ -159,8 +173,12 @@ public class ZimFileSelectFragment extends Fragment
|
||||
}
|
||||
|
||||
public void refreshFragment() {
|
||||
if (mZimFileList == null)
|
||||
if (mZimFileList == null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
return;
|
||||
}
|
||||
|
||||
mHasRefresh = true;
|
||||
presenter.loadLocalZimFileFromDb(context);
|
||||
}
|
||||
|
||||
@ -171,6 +189,7 @@ public class ZimFileSelectFragment extends Fragment
|
||||
mFiles.add(book);
|
||||
mRescanAdapter.notifyDataSetChanged();
|
||||
bookDao.saveBooks(mFiles);
|
||||
checkEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,13 +214,16 @@ public class ZimFileSelectFragment extends Fragment
|
||||
}
|
||||
|
||||
public void getFiles() {
|
||||
if (mZimFileList.getFooterViewsCount() != 0)
|
||||
if (swipeRefreshLayout.isRefreshing() && !mHasRefresh)
|
||||
return;
|
||||
|
||||
TestingUtils.bindResource(ZimFileSelectFragment.class);
|
||||
mZimFileList.addFooterView(progressBar);
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
mZimFileList.setAdapter(mRescanAdapter);
|
||||
|
||||
// Set mHasRefresh to false to prevent loops
|
||||
mHasRefresh = false;
|
||||
|
||||
checkEmpty();
|
||||
|
||||
new FileSearch(context, new FileSearch.ResultListener() {
|
||||
@ -238,9 +260,11 @@ public class ZimFileSelectFragment extends Fragment
|
||||
context.runOnUiThread(() -> {
|
||||
mRescanAdapter.notifyDataSetChanged();
|
||||
bookDao.saveBooks(mFiles);
|
||||
mZimFileList.removeFooterView(progressBar);
|
||||
checkEmpty();
|
||||
TestingUtils.unbindResource(ZimFileSelectFragment.class);
|
||||
|
||||
// Stop swipe refresh animation
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
});
|
||||
}
|
||||
}).scan(PreferenceManager.getDefaultSharedPreferences(context)
|
||||
@ -263,16 +287,6 @@ public class ZimFileSelectFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_rescan_fs:
|
||||
getFiles();
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
|
@ -18,6 +18,7 @@ import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -70,13 +71,14 @@ public class LibraryFragment extends Fragment
|
||||
TextView networkText;
|
||||
@BindView(R.id.network_permission_button)
|
||||
Button permissionButton;
|
||||
private RelativeLayout progressBar;
|
||||
|
||||
@Inject
|
||||
KiwixService kiwixService;
|
||||
|
||||
public LinearLayout llLayout;
|
||||
|
||||
public SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
private ArrayList<Book> books = new ArrayList<>();
|
||||
|
||||
public static DownloadService mService = new DownloadService();
|
||||
@ -116,7 +118,16 @@ public class LibraryFragment extends Fragment
|
||||
// Replace LinearLayout by the type of the root element of the layout you're trying to load
|
||||
llLayout = (LinearLayout) inflater.inflate(R.layout.activity_library, container, false);
|
||||
ButterKnife.bind(this, llLayout);
|
||||
progressBar = (RelativeLayout) inflater.inflate(R.layout.progress_bar, null);
|
||||
|
||||
// SwipeRefreshLayout for the list view
|
||||
swipeRefreshLayout = (SwipeRefreshLayout) llLayout.findViewById(R.id.library_swiperefresh);
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
refreshFragment();
|
||||
}
|
||||
});
|
||||
|
||||
displayScanningContent();
|
||||
libraryAdapter = new LibraryAdapter(super.getContext());
|
||||
libraryList.setAdapter(libraryAdapter);
|
||||
@ -159,19 +170,26 @@ public class LibraryFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public void displayNoNetworkConnection() {
|
||||
libraryList.removeFooterView(progressBar);
|
||||
if (books.size() != 0) {
|
||||
Toast.makeText(super.getActivity(), R.string.no_network_connection, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
networkText.setText(R.string.no_network_msg);
|
||||
networkText.setVisibility(View.VISIBLE);
|
||||
permissionButton.setVisibility(View.GONE);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
swipeRefreshLayout.setEnabled(false);
|
||||
TestingUtils.unbindResource(LibraryFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayScanningContent() {
|
||||
if (libraryList.getFooterViewsCount() == 0) {
|
||||
if (!swipeRefreshLayout.isRefreshing()) {
|
||||
networkText.setVisibility(View.GONE);
|
||||
permissionButton.setVisibility(View.GONE);
|
||||
libraryList.addFooterView(progressBar);
|
||||
swipeRefreshLayout.setEnabled(true);
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
TestingUtils.bindResource(LibraryFragment.class);
|
||||
}
|
||||
}
|
||||
@ -181,7 +199,7 @@ public class LibraryFragment extends Fragment
|
||||
public void stopScanningContent() {
|
||||
networkText.setVisibility(View.GONE);
|
||||
permissionButton.setVisibility(View.GONE);
|
||||
libraryList.removeFooterView(progressBar);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
TestingUtils.unbindResource(LibraryFragment.class);
|
||||
}
|
||||
|
||||
@ -189,6 +207,17 @@ public class LibraryFragment extends Fragment
|
||||
displayNoNetworkConnection();
|
||||
}
|
||||
|
||||
public void refreshFragment() {
|
||||
NetworkInfo network = conMan.getActiveNetworkInfo();
|
||||
if (network == null || !network.isConnected()) {
|
||||
Toast.makeText(super.getActivity(), R.string.no_network_connection, Toast.LENGTH_LONG).show();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
return;
|
||||
}
|
||||
|
||||
networkBroadcastReceiver.onReceive(super.getActivity(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
@ -11,14 +11,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/listBackground">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/library_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="60dp"
|
||||
android:background="?attr/listBackground"
|
||||
android:divider="@null"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/network_permission_text"
|
||||
android:layout_width="wrap_content"
|
||||
@ -37,5 +29,20 @@
|
||||
android:text="@string/proceed"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/library_swiperefresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/library_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="60dp"
|
||||
android:background="?attr/listBackground"
|
||||
android:divider="@null"/>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
@ -20,7 +20,8 @@
|
||||
android:textSize="20sp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<RelativeLayout
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/zim_swiperefresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
@ -45,6 +46,6 @@
|
||||
android:paddingRight="10dp"
|
||||
android:text="@string/error_nozimfilesfound"
|
||||
android:visibility="gone"/>
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_rescan_fs"
|
||||
android:icon="@drawable/action_refresh"
|
||||
android:title="@string/menu_rescan_fs"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
</menu>
|
@ -10,12 +10,6 @@
|
||||
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||
app:iconifiedByDefault="true"
|
||||
app:showAsAction="always|collapseActionView"/>
|
||||
<item
|
||||
android:id="@+id/menu_rescan_fs"
|
||||
android:icon="@drawable/action_refresh"
|
||||
android:title="@string/menu_rescan_fs"
|
||||
android:visible="true"
|
||||
app:showAsAction="always"/>
|
||||
<item
|
||||
android:id="@+id/select_language"
|
||||
android:icon="@drawable/ic_language_white_24dp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user