Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to AppCompatDialog #3222

Closed
wants to merge 8 commits into from

Conversation

agrajaghh
Copy link
Contributor

This migrates from MaterialDialog to AppCompatDialog to eventually eliminate this dependency.
The last other occurence of MaterialDialog is in ReceiveKeyDialog, which I removed in #3225.

I couldn't test the AlertDialog in DeviceProvisioningActivity and in PlayServicesProblemFragment. @rhodey could you help me out there?

android:text="@string/registration_problems__some_possible_problems_include" />

<TableLayout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff-view here is not optimal, I just encapsulated everything in a ScrollView:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:paddingTop="24dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp">

@mcginty
Copy link
Contributor

mcginty commented May 21, 2015

protip: you can append ?w=1 to the url to ignore whitespaces changes in a github diff

@agrajaghh
Copy link
Contributor Author

@mcginty WOW! so much better 😳

@rhodey rhodey self-assigned this May 21, 2015
@rhodey
Copy link
Contributor

rhodey commented May 21, 2015

sure thing @agrajaghh :) I just self assigned and will check back in after I get a chance to test on my N5 & something gingerbread.

@rhodey
Copy link
Contributor

rhodey commented May 21, 2015

@agrajaghh while testing PlayServicesProblemFragment I got this crash.

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
            at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
            at android.support.v7.app.AppCompatDialog.<init>(AppCompatDialog.java:47)
            at android.support.v7.app.AlertDialog.<init>(AlertDialog.java:92)
            at android.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:882)
            at org.thoughtcrime.securesms.PlayServicesProblemFragment.onCreateDialog(PlayServicesProblemFragment.java:38)
            at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:308)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
            at android.app.Activity.performStart(Activity.java:6006)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

@rhodey
Copy link
Contributor

rhodey commented May 21, 2015

also for the record all I did to test this was edit NewConversationActivity.onResume() like so

@Override
  public void onResume() {
    super.onResume();
    dynamicTheme.onResume(this);
    dynamicLanguage.onResume(this);
    getSupportActionBar().setTitle(R.string.AndroidManifest__select_contacts);
    startActivity(new Intent(getBaseContext(), PlayServicesProblemActivity.class));
    finish();
  }

and PlayServicesProblemFragment.onCreateDialog() like so

Dialog dialog = /*GooglePlayServicesUtil.getErrorDialog(code, getActivity(), 9111)*/ null;

then just click the new conversation button.

@agrajaghh
Copy link
Contributor Author

@rhodey Thanks! I could have thought of that by myself 😕

I'm using now android:theme="@style/TextSecure.DialogActivity" for PlayServicesProblemActivity and the AlertDialog is working 😊 The Dialog returned by GooglePlayServicesUtil.getErrorDialog() (tested with code=1) is working as well...

Also tested DeviceProvisioningActivity sucessfully.

@agrajaghh
Copy link
Contributor Author

I removed the material-dialogs dependency now from gradle.build since #3225 is in 2.17.0

});
final AlertDialog dialog = builder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't this be done in the empty onClick() handler above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppCompatDialog doesn't support .autoDismiss(false), so this is a workaround. Otherwise the dialog gets closed immediately. I just tried to stick to the current behaviour (dialog.dismiss() in onPostExecute()). But maybe thats not necessary, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say change handleProvisioning to accept a DialogInterface instead of an AlertDialog and pass along the dialog given to you in the positive button listener.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but how can I prevent the dialog from getting closed immediately? If I do it like that, it will be closed right after the call to handleProvisioning() in the positive button listener and not in onPostExecute() of the ProgressDialogAsyncTask.

What do I miss?

@agrajaghh
Copy link
Contributor Author

rebased

@agrajaghh
Copy link
Contributor Author

rebased and migrated the dialogs from the recent mute/block change

@agrajaghh
Copy link
Contributor Author

@rhodey should I worry about the failed jenkins build?

@rhodey
Copy link
Contributor

rhodey commented Jun 23, 2015

@agrajaghh nope, looks like the test devices we're using for jenkins hit a rate limit with Google Cloud Messaging registration. after making it through ~20 full tests (~400 GCM registrations) all the tests that required GCM registration started to fail persistently.

jenkins just finished running through the last of the pull requests this morning so I just shut that down temporarily. I intend to let it idle for a few hours, maybe a day, and then turn it back on and re-run all of the PRs it marked as failed while somehow trying to avoid the GCM rate limit again.

I don't expect this GCM rate limit will be a problem once we get over the initial backlog, sorry for the trouble.

@agrajaghh
Copy link
Contributor Author

no trouble, just curious, thanks for the explanation ☺️

@agrajaghh
Copy link
Contributor Author

rebased, migrated the dialogs in DeviceListActivity and had to remove
<item name="android:backgroundDimEnabled">false</item> (introduced in 2016fa3) because there isn't a shadow on GB around the dialogs which makes them indistinguishable from the normal activity. If this is a problem I could just disable android:backgroundDimEnabled for >= Honeycomb?

@agrajaghh
Copy link
Contributor Author

since #3883 is in 2.25.0 now, I reverted the last commit because its not needed anymore without android:theme="@style/TextSecure.LightTheme.Popup" for ConversationActivity

Successfully tested on top of 2.25.0 (a3a7f8f) on 5.1.1 and 2.3.7

@agrajaghh
Copy link
Contributor Author

rebased again

should I continue/is this on the nearby agenda? 😟

})
.show();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.DeviceProvisioningActivity_link_this_device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not chain these method calls like before?

AlertDialog dialog = new AlertDialog.builder(this).setTitle(R.blah.blahdeblah)
                                                  .setPositiveBlahblah()
                                                  .create();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.setMessage(content)
.setPositiveButton(R.string.DeviceProvisioningActivity_continue, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd make more sense to have handleProvisioning take in a DialogInterface instead of an AlertDialog and then you can use the normal style of setting OnClickListeners.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel stupid now 😕 I tried that, see my comment above:

but how can I prevent the dialog from getting closed immediately? If I do it like that, it will be closed right after the call to handleProvisioning() in the positive button listener and not in onPostExecute() of the ProgressDialogAsyncTask.

What do I miss?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, my comment got hidden so I didn't think I posted it for some reason!

I see what you're saying now, yeah we have to either do it this way or implement a custom non-alert dialog. The latter is probably less hacky but more effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puh, I thought I missed something obvious 😌

Thats your call, I think these +7 lines are okay and way less than a custom dialog ;)

@mcginty
Copy link
Contributor

mcginty commented Nov 17, 2015

rebased, squashed, migrated RedPhone dialogs, sanity checked (including the device provisioning and play services problems dialogs). time to merge :)

tumblr_lnln95hjr71qjeepdo1_500

in 3.5.0

@mcginty mcginty closed this Nov 17, 2015
mcginty pushed a commit that referenced this pull request Nov 17, 2015
@agrajaghh
Copy link
Contributor Author

wow, I almost lost hope 😝

@agrajaghh agrajaghh deleted the AppCompatDialog branch November 17, 2015 21:37
moxie0 pushed a commit that referenced this pull request Nov 19, 2015
BLeQuerrec pushed a commit to SilenceIM/Silence that referenced this pull request Dec 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants