Initial Android Unified Zim management UI with new download system

This commit is contained in:
mhutti1 2016-07-05 13:32:08 +01:00
parent 873b629756
commit c731ce0f5f
16 changed files with 427 additions and 184 deletions

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.kiwix.kiwixmobile"
android:installLocation="auto"
android:versionCode="30"
android:versionName="2.0">
package="org.kiwix.kiwixmobile"
android:installLocation="auto"
android:versionCode="30"
android:versionName="2.0">
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@ -26,9 +26,9 @@
android:theme="@style/AppTheme"
android:supportsRtl="true">
<activity
android:name=".KiwixMobileActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale"
android:label="@string/app_name">
android:name=".KiwixMobileActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -86,8 +86,8 @@
</intent-filter>
</activity>
<activity
android:name=".ZimFileSelectActivity"
android:label="@string/choose_file">
android:name=".ZimFileSelectFragment"
android:label="@string/choose_file">
<!-- TODO -->
<intent-filter>
@ -104,25 +104,31 @@
<activity android:name=".BookmarksActivity" />
<provider
android:name=".ZimContentProvider"
android:authorities="org.kiwix.zim.base"
android:exported="true" />
android:name=".ZimContentProvider"
android:authorities="org.kiwix.zim.base"
android:exported="true" />
<receiver android:name=".utils.KiwixSearchWidget" >
<receiver android:name=".utils.KiwixSearchWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.TEXT_CLICKED"/>
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.ICON_CLICKED"/>
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.MIC_CLICKED"/>
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.STAR_CLICKED"/>
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.TEXT_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.ICON_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.MIC_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.STAR_CLICKED" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/kiwix_widget_provider_info" />
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/kiwix_widget_provider_info" />
</receiver>
<activity android:name=".LibraryActivity" />
<activity android:name=".LibraryFragment" />
<service android:name=".downloader.DownloadService" />
<activity
android:name=".ZimManageActivity"
android:theme="@style/AppTheme"></activity>
</application>
</manifest>

View File

@ -3,6 +3,7 @@ NEW: Clean history button
NEW: Open new tab in background - settings option
NEW: Kiwix search home screen widget
NEW: Download manager
NEW: Improved ZIM management
FIXED: Opening problem with ZIM filenames with special characters
FIXED: Useless "w820dp" language
FIXED: Failing he, id, yi locales

View File

@ -5,13 +5,36 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="org.kiwix.kiwixmobile.LibraryActivity">
<include layout="@layout/toolbar" />
tools:context=".LibraryFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/library_list" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="visible">
</ProgressBar>
<TextView
android:id="@+id/progressbar_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rescan_fs_warning"
android:paddingTop="10px"
android:textStyle="bold"
android:layout_below="@id/progressBar"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="visible"/>
</RelativeLayout>
</LinearLayout>

View File

@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ZimManageActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@ -5,8 +5,6 @@
android:layout_height="fill_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ZimManageActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:visibility="invisible"
android:src="@android:drawable/stat_sys_download" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -36,14 +36,10 @@
<item
android:id="@+id/menu_openfile"
android:title="@string/menu_openfile"
android:title="@string/menu_zim_manager"
android:icon="@drawable/action_open_file"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_library"
android:title="@string/menu_library"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_searchintext"
android:title="@string/menu_searchintext"

View File

@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ZimManageActivity">
<item
android:id="@+id/menu_rescan_fs"
android:icon="@drawable/action_refresh"
android:title="@string/menu_rescan_fs"
app:showAsAction="always"/>
</menu>

View File

@ -7,5 +7,7 @@
<dimen name="dimen_medium_padding">8dp</dimen>
<dimen name="navigation_width">260dp</dimen>
<dimen name="widget_margin">0dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>

View File

@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<resources>
<string name="menu_openfile">Open File</string>
<string name="menu_zim_manager">Get Content</string>
<string name="menu_help">Help</string>
<string name="menu_home">Home</string>
<string name="menu_forward">Forward</string>
@ -91,4 +91,7 @@
<string name="speech_not_supported">Sorry! Your device does not support speech input</string>
<string name="download_started_library">Download started...</string>
<string name="menu_library">Download ZIM files</string>
<string name="local_zims">Local</string>
<string name="remote_zims">Remote</string>
<string name="zim_manager">Content Management</string>
</resources>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
@ -29,7 +29,11 @@
<item name="spinBars">true</item>
</style>
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView"/>
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView" />
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

View File

@ -49,7 +49,6 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
@ -271,7 +270,6 @@ public class KiwixMobileActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
handleLocaleCheck();
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
@ -772,7 +770,7 @@ public class KiwixMobileActivity extends AppCompatActivity {
break;
case R.id.menu_openfile:
selectZimFile();
manageZimFiles();
break;
case R.id.menu_settings:
@ -791,8 +789,6 @@ public class KiwixMobileActivity extends AppCompatActivity {
}
break;
case R.id.menu_library:
openDownloadManager();
default:
break;
}
@ -801,7 +797,7 @@ public class KiwixMobileActivity extends AppCompatActivity {
}
private void openDownloadManager() {
Intent downloadIntent = new Intent(this, LibraryActivity.class);
Intent downloadIntent = new Intent(this, LibraryFragment.class);
startActivity(downloadIntent);
}
@ -1498,9 +1494,9 @@ public class KiwixMobileActivity extends AppCompatActivity {
}
}
public void selectZimFile() {
public void manageZimFiles() {
refreshBookmarks();
final Intent target = new Intent(this, ZimFileSelectActivity.class);
final Intent target = new Intent(this, ZimManageActivity.class);
target.setAction(Intent.ACTION_GET_CONTENT);
// The MIME data type filter
target.setType("//");
@ -1733,7 +1729,7 @@ public class KiwixMobileActivity extends AppCompatActivity {
} else if (url.startsWith(ZimContentProvider.UI_URI.toString())) {
// To handle links which access user interface (i.p. used in help page)
if (url.equals(ZimContentProvider.UI_URI.toString() + "selectzimfile")) {
selectZimFile();
manageZimFiles();
} else if (url.equals(ZimContentProvider.UI_URI.toString() + "gotohelp")) {
showHelp();
} else {

View File

@ -1,54 +0,0 @@
package org.kiwix.kiwixmobile;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import java.util.List;
import org.kiwix.kiwixmobile.downloader.DownloadIntent;
import org.kiwix.kiwixmobile.downloader.DownloadService;
import org.kiwix.kiwixmobile.library.LibraryAdapter;
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
import org.kiwix.kiwixmobile.network.KiwixService;
import org.kiwix.kiwixmobile.utils.ShortcutUtils;
import rx.android.schedulers.AndroidSchedulers;
import static org.kiwix.kiwixmobile.utils.ShortcutUtils.stringsGetter;
public class LibraryActivity extends AppCompatActivity {
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.library_list) ListView libraryList;
private KiwixService kiwixService;
private List<LibraryNetworkEntity.Book> books;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_library);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
kiwixService = ((KiwixApplication) getApplication()).getKiwixService();
kiwixService.getLibrary()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(library -> {
books = library.getBooks();
libraryList.setAdapter(new LibraryAdapter(LibraryActivity.this, books));
});
libraryList.setOnItemClickListener(
(parent, view, position, id) -> {
Toast.makeText(LibraryActivity.this, stringsGetter(R.string.download_started_library, this), Toast.LENGTH_LONG).show();
Intent service = new Intent(this, DownloadService.class);
service.putExtra(DownloadIntent.DOWNLOAD_URL_PARAMETER, books.get(position).getUrl());
startService(service);
});
}
}

View File

@ -0,0 +1,89 @@
package org.kiwix.kiwixmobile;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import java.util.List;
import org.kiwix.kiwixmobile.downloader.DownloadIntent;
import org.kiwix.kiwixmobile.downloader.DownloadService;
import org.kiwix.kiwixmobile.library.LibraryAdapter;
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
import org.kiwix.kiwixmobile.network.KiwixService;
import org.kiwix.kiwixmobile.utils.ShortcutUtils;
import rx.android.schedulers.AndroidSchedulers;
import static org.kiwix.kiwixmobile.utils.ShortcutUtils.stringsGetter;
public class LibraryFragment extends Fragment {
@BindView(R.id.library_list) ListView libraryList;
@BindView(R.id.progressBar) ProgressBar progressBar;
@BindView(R.id.progressbar_message) TextView progressText;
private KiwixService kiwixService;
private LinearLayout llLayout;
private List<LibraryNetworkEntity.Book> books;
private boolean active;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FragmentActivity faActivity = (FragmentActivity) super.getActivity();
// 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);
// Of course you will want to faActivity and llLayout in the class and not this method to access them in the rest of
// the class, just initialize them here
// Don't use this method, it's handled by inflater.inflate() above :
// setContentView(R.layout.activity_layout);
ButterKnife.bind(this, llLayout);
kiwixService = ((KiwixApplication) super.getActivity().getApplication()).getKiwixService();
kiwixService.getLibrary()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(library -> {
books = library.getBooks();
if (active) {
libraryList.setAdapter(new LibraryAdapter(super.getActivity(), books));
progressBar.setVisibility(View.INVISIBLE);
progressText.setVisibility(View.INVISIBLE);
}
});
libraryList.setOnItemClickListener(
(parent, view, position, id) -> {
Toast.makeText(super.getActivity(), stringsGetter(R.string.download_started_library, super.getActivity()), Toast.LENGTH_LONG).show();
Intent service = new Intent(super.getActivity(), DownloadService.class);
service.putExtra(DownloadIntent.DOWNLOAD_URL_PARAMETER, books.get(position).getUrl());
super.getActivity().startService(service);
});
active = true;
// The FragmentActivity doesn't contain the layout directly so we must use our instance of LinearLayout :
//llLayout.findViewById(R.id.someGuiElement);
// Instead of :
// findViewById(R.id.someGuiElement);
return llLayout; // We must return the loaded Layout
}
@Override
public void onDestroyView() {
super.onDestroyView();
active = false;
}
}

View File

@ -30,6 +30,8 @@ import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.CursorLoader;
@ -38,6 +40,7 @@ import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -48,6 +51,7 @@ import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -59,7 +63,7 @@ import org.kiwix.kiwixmobile.utils.LanguageUtils;
import org.kiwix.kiwixmobile.utils.files.FileSearch;
import org.kiwix.kiwixmobile.utils.files.FileWriter;
public class ZimFileSelectActivity extends AppCompatActivity
public class ZimFileSelectFragment extends Fragment
implements LoaderManager.LoaderCallbacks<Cursor>, OnItemClickListener {
public static final String TAG_KIWIX = "kiwix";
@ -79,44 +83,53 @@ public class ZimFileSelectActivity extends AppCompatActivity
private ProgressBar mProgressBar;
private TextView mProgressBarMessage;
public LinearLayout llLayout;
public static Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FragmentActivity faActivity = (FragmentActivity) super.getActivity();
context = super.getActivity();
// Replace LinearLayout by the type of the root element of the layout you're trying to load
llLayout = (LinearLayout) inflater.inflate(R.layout.zim_list, container, false);
// Of course you will want to faActivity and llLayout in the class and not this method to access them in the rest of
// the class, just initialize them here
new LanguageUtils(this).changeFont(getLayoutInflater());
new LanguageUtils(super.getActivity()).changeFont(super.getActivity().getLayoutInflater());
setContentView(R.layout.zim_list);
setUpToolbar();
mFiles = new ArrayList<DataModel>();
mProgressBar = (ProgressBar) llLayout.findViewById(R.id.progressBar);
mProgressBarMessage = (TextView) llLayout.findViewById(R.id.progressbar_message);
mZimFileList = (ListView) llLayout.findViewById(R.id.zimfilelist);
mZimFileList.setOnItemClickListener(this);
mProgressBar.setVisibility(View.VISIBLE);
setAlpha(true);
checkPermissions();
// Don't use this method, it's handled by inflater.inflate() above :
// setContentView(R.layout.activity_layout);
// The FragmentActivity doesn't contain the layout directly so we must use our instance of LinearLayout :
//llLayout.findViewById(R.id.someGuiElement);
// Instead of :
// findViewById(R.id.someGuiElement);
return llLayout; // We must return the loaded Layout
}
private void setUpToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
public void checkPermissions(){
if (ContextCompat.checkSelfPermission(this,
if (ContextCompat.checkSelfPermission(super.getActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED && Build.VERSION.SDK_INT > 18) {
Toast.makeText(this, getResources().getString(R.string.request_storage), Toast.LENGTH_LONG)
Toast.makeText(super.getActivity(), getResources().getString(R.string.request_storage), Toast.LENGTH_LONG)
.show();
ActivityCompat.requestPermissions(this,
ActivityCompat.requestPermissions(super.getActivity(),
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
KiwixMobileActivity.REQUEST_STORAGE_PERMISSION);
@ -126,21 +139,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
}
public void getFiles(){
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mProgressBarMessage = (TextView) findViewById(R.id.progressbar_message);
mZimFileList = (ListView) findViewById(R.id.zimfilelist);
mZimFileList.setOnItemClickListener(this);
mProgressBar.setVisibility(View.VISIBLE);
setAlpha(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
startQuery();
} else {
new RescanFileSystem().execute();
}
}
@Override
@ -152,7 +151,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getFiles();
} else {
finish();
super.getActivity().finish();
}
return;
}
@ -189,7 +188,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
String sortOrder = MediaStore.Files.FileColumns.TITLE; // Sorted alphabetical
Log.d(TAG_KIWIX, " Performing query for zim files...");
return new CursorLoader(this, uri, projection, query, selectionArgs, sortOrder);
return new CursorLoader(super.getActivity(), uri, projection, query, selectionArgs, sortOrder);
}
@Override
@ -201,7 +200,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
mZimFileList.setAdapter(mRescanAdapter);
// Done here to avoid that shown while loading.
mZimFileList.setEmptyView(findViewById(R.id.zimfilelist_nozimfilesfound_view));
mZimFileList.setEmptyView( llLayout.findViewById(R.id.zimfilelist_nozimfilesfound_view));
if (mProgressBarMessage.getVisibility() == View.GONE) {
mProgressBar.setVisibility(View.GONE);
@ -216,37 +215,8 @@ public class ZimFileSelectActivity extends AppCompatActivity
mCursorAdapter.swapCursor(null);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// Check, if the user has rescanned the file system, if he has, then we want to save this list,
// so this can be shown again, if the activity is recreated (on a device rotation for example)
if (!mFiles.isEmpty()) {
Log.i(TAG_KIWIX, "Saved state of the ListView");
outState.putParcelableArrayList("rescanData", mFiles);
}
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// Get the rescanned data, if available. Create an Adapter for the ListView and display the list
if (savedInstanceState.getParcelableArrayList("rescanData") != null) {
ArrayList<DataModel> data = savedInstanceState.getParcelableArrayList("rescanData");
mRescanAdapter = new RescanDataAdapter(ZimFileSelectActivity.this, 0, data);
mZimFileList.setAdapter(mRescanAdapter);
}
super.onRestoreInstanceState(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_files, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@ -264,7 +234,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG_KIWIX, " mZimFileList.onItemClick");
@ -299,7 +269,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
mCursorAdapter = new SimpleCursorAdapter(
// The Context object
ZimFileSelectActivity.this,
super.getActivity(),
// A layout in XML for one row in the ListView
android.R.layout.simple_list_item_2,
// The cursor, swapped later by cursorloader
@ -311,7 +281,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
// Flags for the Adapter
Adapter.NO_SELECTION);
getSupportLoaderManager().initLoader(LOADER_ID, null, this);
super.getActivity().getSupportLoaderManager().initLoader(LOADER_ID, null, this);
}
// Get the data of our cursor and wrap it all in our ArrayAdapter.
@ -327,7 +297,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
}
}
files = new FileWriter(ZimFileSelectActivity.this, files).getDataModelList();
files = new FileWriter(super.getActivity(), files).getDataModelList();
for (int i = 0; i < files.size(); i++) {
@ -340,21 +310,20 @@ public class ZimFileSelectActivity extends AppCompatActivity
files = new FileSearch().sortDataModel(files);
mFiles = files;
return new RescanDataAdapter(ZimFileSelectActivity.this, 0, mFiles);
return new RescanDataAdapter(super.getActivity(), 0, mFiles);
}
// Get the selected file and return the result to the Activity, that called this Activity
private void finishResult(String path) {
if (path != null) {
File file = new File(path);
Uri uri = Uri.fromFile(file);
Log.i(TAG_KIWIX, "Opening " + uri);
setResult(RESULT_OK, new Intent().setData(uri));
finish();
super.getActivity().setResult(super.getActivity().RESULT_OK, new Intent().setData(uri));
super.getActivity().finish();
} else {
setResult(RESULT_CANCELED);
finish();
super.getActivity().setResult(super.getActivity().RESULT_CANCELED);
super.getActivity().finish();
}
}
@ -430,10 +399,9 @@ public class ZimFileSelectActivity extends AppCompatActivity
mFiles = new FileSearch().findFiles();
return null;
}
@Override
protected void onPostExecute(Void result) {
mRescanAdapter = new RescanDataAdapter(ZimFileSelectActivity.this, 0, mFiles);
mRescanAdapter = new RescanDataAdapter(ZimFileSelectFragment.context, 0, mFiles);
mZimFileList.setAdapter(mRescanAdapter);
@ -441,7 +409,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
mProgressBar.setVisibility(View.GONE);
setAlpha(false);
new FileWriter(ZimFileSelectActivity.this).saveArray(mFiles);
new FileWriter(ZimFileSelectFragment.context).saveArray(mFiles);
super.onPostExecute(result);
}

View File

@ -0,0 +1,135 @@
package org.kiwix.kiwixmobile;
import android.support.design.widget.TabLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class ZimManageActivity extends AppCompatActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.zim_manager);
setUpToolbar();
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
private void setUpToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Don't use this method, it's handled by inflater.inflate() above :
// setContentView(R.layout.activity_layout);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.zim_manager);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
@Override
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);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.menu_rescan_fs){
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
int position = mViewPager.getCurrentItem();
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setCurrentItem(position);
// mViewPager.notify();
}
//noinspection SimplifiableIfStatement
return super.onOptionsItemSelected(item);
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
if (position == 0) {
return new ZimFileSelectFragment();
} else {
return new LibraryFragment();
}
}
@Override
public int getCount() {
// Show 3 total pages.
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getResources().getString(R.string.local_zims);
case 1:
return getResources().getString(R.string.remote_zims);
}
return null;
}
}
}