Use AlertDialogShower

This commit is contained in:
Adeel Zafar 2019-08-16 04:55:14 +05:00
parent 63abcae607
commit 1fd7ae8f7e
4 changed files with 36 additions and 19 deletions

View File

@ -30,23 +30,30 @@ sealed class KiwixDialog(
} }
object LocationPermissionRationale : KiwixDialog( object LocationPermissionRationale : KiwixDialog(
null, R.string.permission_rationale_location, android.R.string.yes, android.R.string.cancel null, R.string.permission_rationale_location, android.R.string.yes, android.R.string.cancel
) )
object StoragePermissionRationale : KiwixDialog( object StoragePermissionRationale : KiwixDialog(
null, R.string.request_storage, android.R.string.yes, android.R.string.cancel null, R.string.request_storage, android.R.string.yes, android.R.string.cancel
) )
object EnableWifiP2pServices : KiwixDialog( object EnableWifiP2pServices : KiwixDialog(
null, R.string.request_enable_wifi, R.string.yes, android.R.string.no null, R.string.request_enable_wifi, R.string.yes, android.R.string.no
) )
object EnableLocationServices : KiwixDialog( object EnableLocationServices : KiwixDialog(
null, R.string.request_enable_location, R.string.yes, android.R.string.no null, R.string.request_enable_location, R.string.yes, android.R.string.no
) )
object HotspotFailed : KiwixDialog(
R.string.hotspot_failed_title,
R.string.hotspot_failed_message,
R.string.go_to_wifi_settings_label,
R.string.cancel
);
data class FileTransferConfirmation(override val args: Array<out Any>) : KiwixDialog( data class FileTransferConfirmation(override val args: Array<out Any>) : KiwixDialog(
null, R.string.transfer_to, R.string.yes, android.R.string.cancel null, R.string.transfer_to, R.string.yes, android.R.string.cancel
), HasBodyFormatArgs { ), HasBodyFormatArgs {
constructor(selectedPeerDeviceName: String) : this(arrayOf(selectedPeerDeviceName)) constructor(selectedPeerDeviceName: String) : this(arrayOf(selectedPeerDeviceName))
} }

View File

@ -38,15 +38,19 @@ import com.google.android.gms.location.LocationSettingsResponse;
import com.google.android.gms.location.LocationSettingsStates; import com.google.android.gms.location.LocationSettingsStates;
import com.google.android.gms.location.LocationSettingsStatusCodes; import com.google.android.gms.location.LocationSettingsStatusCodes;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import dagger.android.AndroidInjection;
import java.io.File; import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import kotlin.Unit; import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.base.BaseActivity; import org.kiwix.kiwixmobile.base.BaseActivity;
import org.kiwix.kiwixmobile.main.MainActivity; import org.kiwix.kiwixmobile.main.MainActivity;
import org.kiwix.kiwixmobile.utils.AlertDialogShower;
import org.kiwix.kiwixmobile.utils.KiwixDialog;
import org.kiwix.kiwixmobile.wifi_hotspot.HotspotService; import org.kiwix.kiwixmobile.wifi_hotspot.HotspotService;
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.SelectionMode; import org.kiwix.kiwixmobile.zim_manager.fileselect_view.SelectionMode;
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BookOnDiskDelegate; import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BookOnDiskDelegate;
@ -68,6 +72,8 @@ public class ZimHostActivity extends BaseActivity implements
@Inject @Inject
ZimHostContract.Presenter presenter; ZimHostContract.Presenter presenter;
@Inject AlertDialogShower alertDialogShower;
public static final String ACTION_TURN_ON_AFTER_O = "Turn_on_hotspot_after_oreo"; public static final String ACTION_TURN_ON_AFTER_O = "Turn_on_hotspot_after_oreo";
public static final String ACTION_TURN_OFF_AFTER_O = "Turn_off_hotspot_after_oreo"; public static final String ACTION_TURN_OFF_AFTER_O = "Turn_off_hotspot_after_oreo";
public static final String ACTION_IS_HOTSPOT_ENABLED = "Is_hotspot_enabled"; public static final String ACTION_IS_HOTSPOT_ENABLED = "Is_hotspot_enabled";
@ -93,6 +99,8 @@ public class ZimHostActivity extends BaseActivity implements
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zim_host); setContentView(R.layout.activity_zim_host);
AndroidInjection.inject(this);
setUpToolbar(); setUpToolbar();
if (savedInstanceState != null) { if (savedInstanceState != null) {
@ -491,7 +499,7 @@ public class ZimHostActivity extends BaseActivity implements
//setupServer(); //setupServer();
} }
private void setupWifiSettingsIntent() { void setupWifiSettingsIntent() {
final Intent intent = new Intent(Intent.ACTION_MAIN, null); final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = final ComponentName cn =
@ -504,19 +512,13 @@ public class ZimHostActivity extends BaseActivity implements
@Override public void hotspotFailed() { @Override public void hotspotFailed() {
//Show a dialog to turn off default hotspot //Show a dialog to turn off default hotspot
AlertDialog.Builder builder = new AlertDialog.Builder(this, dialogStyle()); alertDialogShower.show(KiwixDialog.HotspotFailed.INSTANCE,
new Function0<Unit>() {
builder.setPositiveButton(getString(R.string.go_to_wifi_settings_label), (dialog, id) -> { @Override public Unit invoke() {
//Open wifi settings intent setupWifiSettingsIntent();
setupWifiSettingsIntent(); return Unit.INSTANCE;
}); }
});
builder.setTitle(this.getString(R.string.hotspot_failed_title));
builder.setMessage(
this.getString(R.string.hotspot_failed_message));
AlertDialog dialog = builder.create();
dialog.show();
} }
@Override public void hotspotState(@Nullable Boolean state) { @Override public void hotspotState(@Nullable Boolean state) {

View File

@ -2,7 +2,9 @@ package org.kiwix.kiwixmobile.webserver;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import javax.inject.Singleton;
import org.kiwix.kiwixmobile.di.PerActivity; import org.kiwix.kiwixmobile.di.PerActivity;
import org.kiwix.kiwixmobile.utils.AlertDialogShower;
@Module @Module
public class ZimHostModule { public class ZimHostModule {
@ -12,5 +14,10 @@ public class ZimHostModule {
ZimHostContract.Presenter provideZimHostPresenter(ZimHostPresenter zimHostPresenter) { ZimHostContract.Presenter provideZimHostPresenter(ZimHostPresenter zimHostPresenter) {
return zimHostPresenter; return zimHostPresenter;
} }
@Provides
@Singleton AlertDialogShower provideAlertDialogShower(AlertDialogShower alertDialogShower) {
return alertDialogShower;
}
} }

View File

@ -23,6 +23,7 @@
<string name="choose_file">Select a Content File (*.zim)</string> <string name="choose_file">Select a Content File (*.zim)</string>
<string name="open_in_new_tab">Open link in new tab?</string> <string name="open_in_new_tab">Open link in new tab?</string>
<string name="error_nozimfilesfound">No content found on your device.\nTake a look at the Help Page to get directions on how to load content into Kiwix.\nIf you did put a ZIM file on your device/external storage, you might retry in a minute or restart your device.</string> <string name="error_nozimfilesfound">No content found on your device.\nTake a look at the Help Page to get directions on how to load content into Kiwix.\nIf you did put a ZIM file on your device/external storage, you might retry in a minute or restart your device.</string>
<string name="cancel">Cancel</string>
<string name="hotspot_service_channel_name">Hotspot Service Channel</string> <string name="hotspot_service_channel_name">Hotspot Service Channel</string>
<string name="hotspot_failed_title">Failed to start hotspot</string> <string name="hotspot_failed_title">Failed to start hotspot</string>
<string name="hotspot_failed_message">It seems like your hotspot is already turned on. Please disable your wifi hotspot to continue.</string> <string name="hotspot_failed_message">It seems like your hotspot is already turned on. Please disable your wifi hotspot to continue.</string>