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

View File

@ -2,7 +2,9 @@ package org.kiwix.kiwixmobile.webserver;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
import org.kiwix.kiwixmobile.di.PerActivity;
import org.kiwix.kiwixmobile.utils.AlertDialogShower;
@Module
public class ZimHostModule {
@ -12,5 +14,10 @@ public class ZimHostModule {
ZimHostContract.Presenter provideZimHostPresenter(ZimHostPresenter 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="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="cancel">Cancel</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_message">It seems like your hotspot is already turned on. Please disable your wifi hotspot to continue.</string>