mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 12:42:56 -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>
|
||||||
<activity
|
<activity
|
||||||
android:name=".zim_manager.ZimManageActivity"
|
android:name=".zim_manager.ZimManageActivity"
|
||||||
|
android:launchMode="singleTop"
|
||||||
android:label="@string/choose_file">
|
android:label="@string/choose_file">
|
||||||
|
|
||||||
<!-- TODO -->
|
<!-- TODO -->
|
||||||
@ -192,6 +193,11 @@
|
|||||||
android:resource="@xml/provider_paths" />
|
android:resource="@xml/provider_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<receiver android:name=".zim_manager.DownloadNotificationClickedReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -20,14 +20,15 @@ package org.kiwix.kiwixmobile.database;
|
|||||||
import com.yahoo.squidb.data.SquidCursor;
|
import com.yahoo.squidb.data.SquidCursor;
|
||||||
import com.yahoo.squidb.data.TableModel;
|
import com.yahoo.squidb.data.TableModel;
|
||||||
import com.yahoo.squidb.sql.Query;
|
import com.yahoo.squidb.sql.Query;
|
||||||
import com.yahoo.squidb.sql.Table;
|
|
||||||
import com.yahoo.squidb.sql.TableStatement;
|
import com.yahoo.squidb.sql.TableStatement;
|
||||||
import io.reactivex.Flowable;
|
import io.reactivex.Flowable;
|
||||||
import io.reactivex.processors.BehaviorProcessor;
|
import io.reactivex.processors.BehaviorProcessor;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import kotlin.collections.ArraysKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.kiwix.kiwixmobile.database.entity.DownloadDatabaseEntity;
|
import org.kiwix.kiwixmobile.database.entity.DownloadDatabaseEntity;
|
||||||
import org.kiwix.kiwixmobile.downloader.model.DownloadModel;
|
import org.kiwix.kiwixmobile.downloader.model.DownloadModel;
|
||||||
@ -60,6 +61,13 @@ public class DownloadDao extends BaseDao{
|
|||||||
) == 0;
|
) == 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) {
|
public void delete(@NotNull Long... downloadIds) {
|
||||||
if (downloadIds.length > 0) {
|
if (downloadIds.length > 0) {
|
||||||
kiwixDatabase.deleteWhere(DownloadDatabaseEntity.class,
|
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.JNIModule;
|
||||||
import org.kiwix.kiwixmobile.di.modules.NetworkModule;
|
import org.kiwix.kiwixmobile.di.modules.NetworkModule;
|
||||||
import org.kiwix.kiwixmobile.downloader.DownloadService;
|
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.settings.KiwixSettingsActivity;
|
||||||
import org.kiwix.kiwixmobile.views.AutoCompleteAdapter;
|
import org.kiwix.kiwixmobile.views.AutoCompleteAdapter;
|
||||||
import org.kiwix.kiwixmobile.views.web.KiwixWebView;
|
import org.kiwix.kiwixmobile.views.web.KiwixWebView;
|
||||||
|
import org.kiwix.kiwixmobile.zim_manager.DownloadNotificationClickedReceiver;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
@ -61,4 +61,6 @@ public interface ApplicationComponent {
|
|||||||
void inject(KiwixSettingsActivity.PrefsFragment prefsFragment);
|
void inject(KiwixSettingsActivity.PrefsFragment prefsFragment);
|
||||||
|
|
||||||
void inject(AutoCompleteAdapter autoCompleteAdapter);
|
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
|
adapter = mSectionsPagerAdapter
|
||||||
offscreenPageLimit = 2
|
offscreenPageLimit = 2
|
||||||
tabs.setupWithViewPager(this)
|
tabs.setupWithViewPager(this)
|
||||||
currentItem = intent.getIntExtra(TAB_EXTRA, 0)
|
|
||||||
addOnPageChangeListener(SimplePageChangeListener(this@ZimManageActivity::updateMenu))
|
addOnPageChangeListener(SimplePageChangeListener(this@ZimManageActivity::updateMenu))
|
||||||
}
|
}
|
||||||
zimManageViewModel.languageItems.observe(this, Observer {
|
zimManageViewModel.languageItems.observe(this, Observer {
|
||||||
onLanguageItemsForDialogUpdated(it!!)
|
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>) {
|
private fun onLanguageItemsForDialogUpdated(languages: List<Language>) {
|
||||||
@ -100,7 +111,7 @@ class ZimManageActivity : BaseActivity() {
|
|||||||
.apply {
|
.apply {
|
||||||
onOkClicked = {
|
onOkClicked = {
|
||||||
Flowable.fromCallable {
|
Flowable.fromCallable {
|
||||||
languagesDao.saveFilteredLanguages(it.sortedBy(Language::language))
|
languagesDao.saveFilteredLanguages(it)
|
||||||
}
|
}
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe()
|
.subscribe()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user