Fixed NPEs in identity creation dialogs

This commit is contained in:
Christian Basler 2016-10-07 23:06:47 +02:00
parent 0efd17a356
commit a1fb11357b
2 changed files with 12 additions and 7 deletions

View File

@ -24,6 +24,7 @@ import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatDialogFragment; import android.support.v7.app.AppCompatDialogFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -63,9 +64,10 @@ public class AddIdentityDialogFragment extends AppCompatDialogFragment {
view.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Context ctx = getActivity().getBaseContext();
switch (radioGroup.getCheckedRadioButtonId()) { switch (radioGroup.getCheckedRadioButtonId()) {
case R.id.create_identity: case R.id.create_identity:
Toast.makeText(getActivity(), Toast.makeText(ctx,
R.string.toast_long_running_operation, R.string.toast_long_running_operation,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
new AsyncTask<Void, Void, BitmessageAddress>() { new AsyncTask<Void, Void, BitmessageAddress>() {
@ -76,7 +78,7 @@ public class AddIdentityDialogFragment extends AppCompatDialogFragment {
@Override @Override
protected void onPostExecute(BitmessageAddress chan) { protected void onPostExecute(BitmessageAddress chan) {
Toast.makeText(getActivity(), Toast.makeText(ctx,
R.string.toast_identity_created, R.string.toast_identity_created,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
MainActivity mainActivity = MainActivity.getInstance(); MainActivity mainActivity = MainActivity.getInstance();
@ -87,7 +89,7 @@ public class AddIdentityDialogFragment extends AppCompatDialogFragment {
}.execute(); }.execute();
break; break;
case R.id.import_identity: case R.id.import_identity:
startActivity(new Intent(getActivity(), ImportIdentityActivity.class)); startActivity(new Intent(ctx, ImportIdentityActivity.class));
break; break;
case R.id.add_chan: case R.id.add_chan:
addChanDialog(); addChanDialog();
@ -113,17 +115,19 @@ public class AddIdentityDialogFragment extends AppCompatDialogFragment {
} }
private void addChanDialog() { private void addChanDialog() {
FragmentActivity activity = getActivity();
final Context ctx = activity.getBaseContext();
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
final View dialogView = getActivity().getLayoutInflater() final View dialogView = activity.getLayoutInflater()
.inflate(R.layout.dialog_input_passphrase, null); .inflate(R.layout.dialog_input_passphrase, null);
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(activity)
.setTitle(R.string.add_chan) .setTitle(R.string.add_chan)
.setView(dialogView) .setView(dialogView)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
TextView passphrase = (TextView) dialogView.findViewById(R.id.passphrase); TextView passphrase = (TextView) dialogView.findViewById(R.id.passphrase);
Toast.makeText(getActivity(), R.string.toast_long_running_operation, Toast.makeText(ctx, R.string.toast_long_running_operation,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
new AsyncTask<String, Void, BitmessageAddress>() { new AsyncTask<String, Void, BitmessageAddress>() {
@Override @Override
@ -137,7 +141,7 @@ public class AddIdentityDialogFragment extends AppCompatDialogFragment {
@Override @Override
protected void onPostExecute(BitmessageAddress chan) { protected void onPostExecute(BitmessageAddress chan) {
Toast.makeText(getActivity(), Toast.makeText(ctx,
R.string.toast_chan_created, R.string.toast_chan_created,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
MainActivity mainActivity = MainActivity.getInstance(); MainActivity mainActivity = MainActivity.getInstance();

View File

@ -103,4 +103,5 @@ Als Alternative kann in den Einstellungen ein vertrauenswürdiger Knoten konfigu
<string name="select_file_title">Datei auswählen</string> <string name="select_file_title">Datei auswählen</string>
<string name="select_identities_to_import">Bitte wähle die zu importierenden Identitäten:</string> <string name="select_identities_to_import">Bitte wähle die zu importierenden Identitäten:</string>
<string name="import_input_description">Du kannst einfach den Inhalt eines Exports oder einer keys.dat-Datei einfügen</string> <string name="import_input_description">Du kannst einfach den Inhalt eines Exports oder einer keys.dat-Datei einfügen</string>
<string name="name">Name</string>
</resources> </resources>