added confirm dialog for list editor
This commit is contained in:
parent
bd77de011d
commit
c44a269315
|
@ -1,5 +1,6 @@
|
||||||
package org.nuclearfog.twidda.activity;
|
package org.nuclearfog.twidda.activity;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
@ -8,6 +9,8 @@ import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog.Builder;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import org.nuclearfog.twidda.R;
|
import org.nuclearfog.twidda.R;
|
||||||
|
@ -22,11 +25,29 @@ import static android.view.View.INVISIBLE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static org.nuclearfog.twidda.activity.TwitterList.RET_LIST_CREATED;
|
import static org.nuclearfog.twidda.activity.TwitterList.RET_LIST_CREATED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Popup activity for the list editor
|
||||||
|
*/
|
||||||
public class ListPopup extends AppCompatActivity implements OnClickListener {
|
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";
|
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";
|
public static final String KEY_LIST_TITLE = "list_title";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key for the list description
|
||||||
|
*/
|
||||||
public static final String KEY_LIST_DESCR = "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";
|
public static final String KEY_LIST_VISIB = "list_visibility";
|
||||||
|
|
||||||
private UserListUpdater updaterAsync;
|
private UserListUpdater updaterAsync;
|
||||||
|
@ -34,6 +55,7 @@ public class ListPopup extends AppCompatActivity implements OnClickListener {
|
||||||
private CompoundButton visibility;
|
private CompoundButton visibility;
|
||||||
private View progressCircle;
|
private View progressCircle;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle b) {
|
protected void onCreate(Bundle b) {
|
||||||
super.onCreate(b);
|
super.onCreate(b);
|
||||||
|
@ -56,6 +78,33 @@ public class ListPopup extends AppCompatActivity implements OnClickListener {
|
||||||
update.setOnClickListener(this);
|
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
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (view.getId() == R.id.userlist_create_list) {
|
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() {
|
public void startLoading() {
|
||||||
progressCircle.setVisibility(VISIBLE);
|
progressCircle.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* called when a list was updated successfully
|
||||||
|
*/
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null && extras.containsKey(KEY_LIST_ID)) {
|
if (extras != null && extras.containsKey(KEY_LIST_ID)) {
|
||||||
Toast.makeText(this, R.string.info_list_updated, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.info_list_updated, Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} 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();
|
Toast.makeText(this, R.string.info_list_created, Toast.LENGTH_SHORT).show();
|
||||||
setResult(RET_LIST_CREATED);
|
setResult(RET_LIST_CREATED);
|
||||||
}
|
}
|
||||||
finish();
|
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)
|
if (err != null)
|
||||||
ErrorHandler.handleFailure(this, err);
|
ErrorHandler.handleFailure(this, err);
|
||||||
progressCircle.setVisibility(INVISIBLE);
|
progressCircle.setVisibility(INVISIBLE);
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<CheckBox
|
||||||
android:id="@+id/list_edit_public_sw"
|
android:id="@+id/list_edit_public_sw"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -76,6 +76,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="dark_transparent">#af000000</color>
|
|
||||||
<color name="half_transparent">#40000000</color>
|
<color name="half_transparent">#40000000</color>
|
||||||
<color name="bright_transparent">#afffffff</color>
|
<color name="bright_transparent">#afffffff</color>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue