added confirm dialog for list editor
This commit is contained in:
parent
bd77de011d
commit
c44a269315
|
@ -1,5 +1,6 @@
|
|||
package org.nuclearfog.twidda.activity;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -8,6 +9,8 @@ import android.widget.CompoundButton;
|
|||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog.Builder;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
|
@ -22,11 +25,29 @@ import static android.view.View.INVISIBLE;
|
|||
import static android.view.View.VISIBLE;
|
||||
import static org.nuclearfog.twidda.activity.TwitterList.RET_LIST_CREATED;
|
||||
|
||||
/**
|
||||
* Popup activity for the list editor
|
||||
*/
|
||||
public class ListPopup extends AppCompatActivity implements OnClickListener {
|
||||
|
||||
/**
|
||||
* Key for the list ID of the list if an existing list should be updated
|
||||
*/
|
||||
public static final String KEY_LIST_ID = "list_id";
|
||||
|
||||
/**
|
||||
* Key for the title of the list
|
||||
*/
|
||||
public static final String KEY_LIST_TITLE = "list_title";
|
||||
|
||||
/**
|
||||
* Key for the list description
|
||||
*/
|
||||
public static final String KEY_LIST_DESCR = "list_description";
|
||||
|
||||
/**
|
||||
* Key for the visibility of the list
|
||||
*/
|
||||
public static final String KEY_LIST_VISIB = "list_visibility";
|
||||
|
||||
private UserListUpdater updaterAsync;
|
||||
|
@ -34,6 +55,7 @@ public class ListPopup extends AppCompatActivity implements OnClickListener {
|
|||
private CompoundButton visibility;
|
||||
private View progressCircle;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
|
@ -56,6 +78,33 @@ public class ListPopup extends AppCompatActivity implements OnClickListener {
|
|||
update.setOnClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
String titleStr = "";
|
||||
String descrStr = "";
|
||||
if (extras != null) {
|
||||
titleStr = extras.getString(KEY_LIST_TITLE, titleStr);
|
||||
descrStr = extras.getString(KEY_LIST_DESCR, descrStr);
|
||||
}
|
||||
if (titleStr.equals(title.getText().toString()) && descrStr.equals(description.getText().toString())) {
|
||||
super.onBackPressed();
|
||||
} else {
|
||||
Builder alertDialog = new Builder(this, R.style.ConfirmDialog);
|
||||
alertDialog.setMessage(R.string.confirm_discard);
|
||||
alertDialog.setNegativeButton(R.string.confirm_no, null);
|
||||
alertDialog.setPositiveButton(R.string.confirm_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view.getId() == R.id.userlist_create_list) {
|
||||
|
@ -79,26 +128,34 @@ public class ListPopup extends AppCompatActivity implements OnClickListener {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* called when an update starts
|
||||
*/
|
||||
public void startLoading() {
|
||||
progressCircle.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* called when a list was updated successfully
|
||||
*/
|
||||
public void onSuccess() {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras != null && extras.containsKey(KEY_LIST_ID)) {
|
||||
Toast.makeText(this, R.string.info_list_updated, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
// if no list ID is defined, it's a new list
|
||||
// it's a new list, if no list ID is defined
|
||||
Toast.makeText(this, R.string.info_list_created, Toast.LENGTH_SHORT).show();
|
||||
setResult(RET_LIST_CREATED);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
public void onError(EngineException err) {
|
||||
/**
|
||||
* called when an error occurs while updating a list
|
||||
*
|
||||
* @param err twitter exception
|
||||
*/
|
||||
public void onError(@Nullable EngineException err) {
|
||||
if (err != null)
|
||||
ErrorHandler.handleFailure(this, err);
|
||||
progressCircle.setVisibility(INVISIBLE);
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
android:gravity="end"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
<CheckBox
|
||||
android:id="@+id/list_edit_public_sw"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -76,6 +76,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="dark_transparent">#af000000</color>
|
||||
<color name="half_transparent">#40000000</color>
|
||||
<color name="bright_transparent">#afffffff</color>
|
||||
</resources>
|
Loading…
Reference in New Issue