mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 04:33:54 -04:00
Show downloads tab when notification is clicked on
This commit is contained in:
parent
73690fbd23
commit
2d19903708
@ -130,6 +130,7 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".zim_manager.ZimManageActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:label="@string/choose_file">
|
||||
|
||||
<!-- TODO -->
|
||||
@ -192,6 +193,11 @@
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
|
||||
<receiver android:name=".zim_manager.DownloadNotificationClickedReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -20,27 +20,28 @@ package org.kiwix.kiwixmobile.database;
|
||||
import com.yahoo.squidb.data.SquidCursor;
|
||||
import com.yahoo.squidb.data.TableModel;
|
||||
import com.yahoo.squidb.sql.Query;
|
||||
import com.yahoo.squidb.sql.Table;
|
||||
import com.yahoo.squidb.sql.TableStatement;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.processors.BehaviorProcessor;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.kiwix.kiwixmobile.database.entity.DownloadDatabaseEntity;
|
||||
import org.kiwix.kiwixmobile.downloader.model.DownloadModel;
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||
|
||||
public class DownloadDao extends BaseDao{
|
||||
public class DownloadDao extends BaseDao {
|
||||
|
||||
private final BehaviorProcessor<List<DownloadModel>> downloadsProcessor =
|
||||
BehaviorProcessor.create();
|
||||
|
||||
@Inject
|
||||
public DownloadDao(KiwixDatabase kiwixDatabase) {
|
||||
super(kiwixDatabase,DownloadDatabaseEntity.TABLE);
|
||||
super(kiwixDatabase, DownloadDatabaseEntity.TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,8 +50,8 @@ public class DownloadDao extends BaseDao{
|
||||
}
|
||||
|
||||
public void insert(final DownloadModel downloadModel) {
|
||||
kiwixDatabase.persistWithOnConflict(databaseEntity(downloadModel),
|
||||
TableStatement.ConflictAlgorithm.REPLACE);
|
||||
kiwixDatabase.persistWithOnConflict(databaseEntity(downloadModel),
|
||||
TableStatement.ConflictAlgorithm.REPLACE);
|
||||
}
|
||||
|
||||
public boolean doesNotAlreadyExist(LibraryNetworkEntity.Book book) {
|
||||
@ -60,6 +61,13 @@ public class DownloadDao extends BaseDao{
|
||||
) == 0;
|
||||
}
|
||||
|
||||
public boolean containsAny(@NotNull Long[] downloadIds) {
|
||||
return kiwixDatabase.count(
|
||||
DownloadDatabaseEntity.class,
|
||||
DownloadDatabaseEntity.DOWNLOAD_ID.in((Object[]) downloadIds)
|
||||
) > 0;
|
||||
}
|
||||
|
||||
public void delete(@NotNull Long... downloadIds) {
|
||||
if (downloadIds.length > 0) {
|
||||
kiwixDatabase.deleteWhere(DownloadDatabaseEntity.class,
|
||||
|
@ -27,10 +27,10 @@ import org.kiwix.kiwixmobile.di.modules.ApplicationModule;
|
||||
import org.kiwix.kiwixmobile.di.modules.JNIModule;
|
||||
import org.kiwix.kiwixmobile.di.modules.NetworkModule;
|
||||
import org.kiwix.kiwixmobile.downloader.DownloadService;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryAdapter;
|
||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
||||
import org.kiwix.kiwixmobile.views.AutoCompleteAdapter;
|
||||
import org.kiwix.kiwixmobile.views.web.KiwixWebView;
|
||||
import org.kiwix.kiwixmobile.zim_manager.DownloadNotificationClickedReceiver;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
@ -61,4 +61,6 @@ public interface ApplicationComponent {
|
||||
void inject(KiwixSettingsActivity.PrefsFragment prefsFragment);
|
||||
|
||||
void inject(AutoCompleteAdapter autoCompleteAdapter);
|
||||
|
||||
void inject(DownloadNotificationClickedReceiver downloadNotificationClickedReceiver);
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (C) 2018 Kiwix <android.kiwix.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.zim_manager
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import org.kiwix.kiwixmobile.KiwixApplication
|
||||
import org.kiwix.kiwixmobile.database.DownloadDao
|
||||
import javax.inject.Inject
|
||||
|
||||
class DownloadNotificationClickedReceiver : BaseBroadcastReceiver() {
|
||||
override val action: String = DownloadManager.ACTION_NOTIFICATION_CLICKED
|
||||
|
||||
@Inject lateinit var downloadDao: DownloadDao
|
||||
|
||||
override fun onIntentWithActionReceived(
|
||||
context: Context,
|
||||
intent: Intent
|
||||
) {
|
||||
KiwixApplication.getApplicationComponent()
|
||||
.inject(this)
|
||||
val longArray =
|
||||
intent.extras?.getLongArray(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS)
|
||||
?: longArrayOf()
|
||||
if (downloadDao.containsAny(longArray.toTypedArray())) {
|
||||
context.startActivity(
|
||||
Intent(context, ZimManageActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
putExtra(ZimManageActivity.TAB_EXTRA, 2)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -84,12 +84,23 @@ class ZimManageActivity : BaseActivity() {
|
||||
adapter = mSectionsPagerAdapter
|
||||
offscreenPageLimit = 2
|
||||
tabs.setupWithViewPager(this)
|
||||
currentItem = intent.getIntExtra(TAB_EXTRA, 0)
|
||||
addOnPageChangeListener(SimplePageChangeListener(this@ZimManageActivity::updateMenu))
|
||||
}
|
||||
zimManageViewModel.languageItems.observe(this, Observer {
|
||||
onLanguageItemsForDialogUpdated(it!!)
|
||||
})
|
||||
setViewPagerPositionFromIntent(intent)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
setViewPagerPositionFromIntent(intent)
|
||||
}
|
||||
|
||||
private fun setViewPagerPositionFromIntent(intent: Intent?) {
|
||||
if (intent?.hasExtra(TAB_EXTRA) == true) {
|
||||
manageViewPager.currentItem = intent.getIntExtra(TAB_EXTRA, 0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onLanguageItemsForDialogUpdated(languages: List<Language>) {
|
||||
@ -100,7 +111,7 @@ class ZimManageActivity : BaseActivity() {
|
||||
.apply {
|
||||
onOkClicked = {
|
||||
Flowable.fromCallable {
|
||||
languagesDao.saveFilteredLanguages(it.sortedBy(Language::language))
|
||||
languagesDao.saveFilteredLanguages(it)
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
|
Loading…
x
Reference in New Issue
Block a user