removed enum classes, added comments, bug fix

This commit is contained in:
nuclearfog 2022-07-14 20:56:55 +02:00
parent fbc489056c
commit d9fc695fc9
No known key found for this signature in database
GPG Key ID: AA0271FBE406DB98
20 changed files with 260 additions and 175 deletions

View File

@ -8,7 +8,7 @@ import androidx.appcompat.app.AppCompatDelegate;
import org.nuclearfog.twidda.backend.utils.TLSSocketFactory;
/**
* custom application class to initialize support for old android versions and proxy settings
* custom application class to to add support for Android devices below API 21
*
* @author nuclearfog
*/
@ -18,12 +18,14 @@ public class CompatApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// enable support for vector drawables
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
// check and enable TLS 1.2 support
// check if TLS 1.2 is supported
// enable experimental TLS 1.2 support
TLSSocketFactory.setSupportTLS();
}
}

View File

@ -154,7 +154,7 @@ public class MessageAdapter extends Adapter<ViewHolder> {
if (position != NO_POSITION) {
DirectMessage message = data.get(position);
if (message != null) {
itemClickListener.onClick(message, OnMessageClickListener.Action.ANSWER);
itemClickListener.onClick(message, OnMessageClickListener.ANSWER);
}
}
}
@ -166,7 +166,7 @@ public class MessageAdapter extends Adapter<ViewHolder> {
if (position != NO_POSITION) {
DirectMessage message = data.get(position);
if (message != null) {
itemClickListener.onClick(message, OnMessageClickListener.Action.DELETE);
itemClickListener.onClick(message, OnMessageClickListener.DELETE);
}
}
}
@ -178,7 +178,7 @@ public class MessageAdapter extends Adapter<ViewHolder> {
if (position != NO_POSITION) {
DirectMessage message = data.get(position);
if (message != null) {
itemClickListener.onClick(message, OnMessageClickListener.Action.PROFILE);
itemClickListener.onClick(message, OnMessageClickListener.PROFILE);
}
}
}
@ -190,7 +190,7 @@ public class MessageAdapter extends Adapter<ViewHolder> {
if (position != NO_POSITION) {
DirectMessage message = data.get(position);
if (message != null) {
itemClickListener.onClick(message, OnMessageClickListener.Action.MEDIA);
itemClickListener.onClick(message, OnMessageClickListener.MEDIA);
}
}
}
@ -278,22 +278,32 @@ public class MessageAdapter extends Adapter<ViewHolder> {
public interface OnMessageClickListener extends OnTagClickListener {
/**
* Actions performed by clicking the buttons
* indicates that the "answer" button was clicked
*/
enum Action {
ANSWER,
DELETE,
PROFILE,
MEDIA
}
int ANSWER = 1;
/**
* indicates that the "delete" button was clicked
*/
int DELETE = 10;
/**
* indicates that the profile image was clicked
*/
int PROFILE = 100;
/**
* indicates that the media button was clicked
*/
int MEDIA = 1000;
/**
* called when a button was clicked
*
* @param message Message information
* @param action what button was clicked
* @param action what button was clicked {@link #ANSWER,#DELETE,#PROFILE,#MEDIA}
*/
void onClick(DirectMessage message, Action action);
void onClick(DirectMessage message, int action);
/**
* called when the footer was clicked

View File

@ -24,7 +24,7 @@ public class UserlistUpdate {
* @param title Title of the list
* @param description short description of the list
* @param isPublic true if list should be public
* @param listId ID of the list to update or {@link UserlistUpdate#NEW_LIST} to create a new list
* @param listId ID of the list to update or {@link #NEW_LIST} to create a new list
*/
public UserlistUpdate(String title, String description, boolean isPublic, long listId) {
this.title = title;

View File

@ -718,7 +718,7 @@ public class AppDatabase {
*
* @param user user information
* @param db SQLITE DB
* @param mode SQLITE mode {@link SQLiteDatabase#CONFLICT_IGNORE} or {@link SQLiteDatabase#CONFLICT_REPLACE}
* @param mode SQLITE mode {@link SQLiteDatabase#CONFLICT_IGNORE,SQLiteDatabase#CONFLICT_REPLACE}
*/
private void storeUser(User user, SQLiteDatabase db, int mode) {
int register = getUserRegister(db, user.getId());

View File

@ -27,7 +27,6 @@ import org.nuclearfog.twidda.backend.async.MessageUpdater;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog.OnProgressStopListener;
@ -99,7 +98,7 @@ public class MessageEditor extends MediaActivity implements OnClickListener, OnC
if (receiver.getText().length() == 0 && message.getText().length() == 0 && holder.getMediaUri() == null) {
super.onBackPressed();
} else {
confirmDialog.show(DialogType.MESSAGE_EDITOR_LEAVE);
confirmDialog.show(ConfirmDialog.MESSAGE_EDITOR_LEAVE);
}
}
@ -167,13 +166,13 @@ public class MessageEditor extends MediaActivity implements OnClickListener, OnC
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
// retry sending message
if (type == DialogType.MESSAGE_EDITOR_ERROR) {
if (type == ConfirmDialog.MESSAGE_EDITOR_ERROR) {
sendMessage();
}
// leave message editor
else if (type == DialogType.MESSAGE_EDITOR_LEAVE) {
else if (type == ConfirmDialog.MESSAGE_EDITOR_LEAVE) {
finish();
}
}
@ -193,8 +192,7 @@ public class MessageEditor extends MediaActivity implements OnClickListener, OnC
*/
public void onError(@Nullable ErrorHandler.TwitterError error) {
String message = ErrorHandler.getErrorMessage(this, error);
confirmDialog.setMessage(message);
confirmDialog.show(DialogType.MESSAGE_EDITOR_ERROR);
confirmDialog.show(ConfirmDialog.MESSAGE_EDITOR_ERROR, message);
loadingCircle.dismiss();
}

View File

@ -42,7 +42,6 @@ import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog.OnProgressStopListener;
@ -167,7 +166,7 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, OnP
} else if (username.isEmpty() && userLink.isEmpty() && userLoc.isEmpty() && userBio.isEmpty()) {
finish();
} else {
confirmDialog.show(DialogType.PROFILE_EDITOR_LEAVE);
confirmDialog.show(ConfirmDialog.PROFILE_EDITOR_LEAVE);
}
}
@ -241,13 +240,13 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, OnP
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
// leave without settings
if (type == DialogType.PROFILE_EDITOR_LEAVE) {
if (type == ConfirmDialog.PROFILE_EDITOR_LEAVE) {
finish();
}
// retry
else if (type == DialogType.PROFILE_EDITOR_ERROR) {
else if (type == ConfirmDialog.PROFILE_EDITOR_ERROR) {
updateUser();
}
}
@ -284,8 +283,7 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, OnP
*/
public void onError(ErrorHandler.TwitterError err) {
String message = ErrorHandler.getErrorMessage(this, err);
confirmDialog.setMessage(message);
confirmDialog.show(DialogType.PROFILE_EDITOR_ERROR);
confirmDialog.show(ConfirmDialog.PROFILE_EDITOR_ERROR, message);
loadingCircle.dismiss();
}

View File

@ -4,7 +4,6 @@ import static android.os.AsyncTask.Status.RUNNING;
import static android.view.View.GONE;
import static android.view.View.OnClickListener;
import static android.view.View.VISIBLE;
import static org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import android.app.Dialog;
import android.content.Context;
@ -283,7 +282,7 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
if (saveConnectionSettings()) {
super.onBackPressed();
} else {
confirmDialog.show(DialogType.WRONG_PROXY);
confirmDialog.show(ConfirmDialog.WRONG_PROXY);
}
}
@ -316,9 +315,9 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
// confirm log out
if (type == DialogType.APP_LOG_OUT) {
if (type == ConfirmDialog.APP_LOG_OUT) {
settings.logout();
// remove account from database
AccountDatabase accountDB = new AccountDatabase(this);
@ -327,12 +326,12 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
finish();
}
// confirm delete app data and cache
else if (type == DialogType.DELETE_APP_DATA) {
else if (type == ConfirmDialog.DELETE_APP_DATA) {
DatabaseAdapter.deleteDatabase(this);
setResult(RETURN_DATA_CLEARED);
}
// confirm leaving without saving proxy changes
else if (type == DialogType.WRONG_PROXY) {
else if (type == ConfirmDialog.WRONG_PROXY) {
// exit without saving proxy settings
finish();
}
@ -343,11 +342,11 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
public void onClick(View v) {
// delete database
if (v.getId() == R.id.delete_db) {
confirmDialog.show(DialogType.DELETE_APP_DATA);
confirmDialog.show(ConfirmDialog.DELETE_APP_DATA);
}
// logout from twitter
else if (v.getId() == R.id.logout) {
confirmDialog.show(DialogType.APP_LOG_OUT);
confirmDialog.show(ConfirmDialog.APP_LOG_OUT);
}
// set background color
else if (v.getId() == R.id.color_background) {

View File

@ -57,7 +57,6 @@ import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Tweet;
import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.ui.dialogs.LinkDialog;
import org.nuclearfog.twidda.ui.fragments.TweetFragment;
@ -333,7 +332,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
User author = clickedTweet.getAuthor();
// Delete tweet option
if (item.getItemId() == R.id.menu_tweet_delete) {
confirmDialog.show(DialogType.TWEET_DELETE);
confirmDialog.show(ConfirmDialog.TWEET_DELETE);
}
// hide tweet
else if (item.getItemId() == R.id.menu_tweet_hide) {
@ -462,7 +461,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
mediaIntent.putExtra(VideoViewer.ENABLE_VIDEO_CONTROLS, true);
startActivity(mediaIntent);
} else {
confirmDialog.show(DialogType.PROXY_CONFIRM);
confirmDialog.show(ConfirmDialog.PROXY_CONFIRM);
}
}
// open embedded gif link
@ -519,16 +518,16 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
if (tweet != null) {
Tweet clickedTweet = tweet;
if (tweet.getEmbeddedTweet() != null) {
clickedTweet = tweet.getEmbeddedTweet();
}
if (type == DialogType.TWEET_DELETE) {
if (type == ConfirmDialog.TWEET_DELETE) {
statusAsync = new TweetAction(this, TweetAction.DELETE);
statusAsync.execute(clickedTweet.getId(), clickedTweet.getRetweetId());
} else if (type == DialogType.PROXY_CONFIRM) {
} else if (type == ConfirmDialog.PROXY_CONFIRM) {
settings.setIgnoreProxyWarning(rememberChoice);
Uri link = clickedTweet.getMediaUris()[0];

View File

@ -32,7 +32,6 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog.OnProgressStopListener;
@ -310,13 +309,13 @@ public class TweetEditor extends MediaActivity implements OnClickListener, OnPro
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
// retry uploading tweet
if (type == DialogType.TWEET_EDITOR_ERROR) {
if (type == ConfirmDialog.TWEET_EDITOR_ERROR) {
updateTweet();
}
// leave editor
else if (type == DialogType.TWEET_EDITOR_LEAVE) {
else if (type == ConfirmDialog.TWEET_EDITOR_LEAVE) {
finish();
}
}
@ -334,8 +333,7 @@ public class TweetEditor extends MediaActivity implements OnClickListener, OnPro
*/
public void onError(@Nullable ErrorHandler.TwitterError error) {
String message = ErrorHandler.getErrorMessage(this, error);
confirmDialog.setMessage(message);
confirmDialog.show(DialogType.TWEET_EDITOR_ERROR);
confirmDialog.show(ConfirmDialog.TWEET_EDITOR_ERROR, message);
loadingCircle.dismiss();
}
@ -344,7 +342,7 @@ public class TweetEditor extends MediaActivity implements OnClickListener, OnPro
*/
private void showClosingMsg() {
if (tweetText.length() > 0 || tweetUpdate.mediaCount() > 0 || tweetUpdate.hasLocation()) {
confirmDialog.show(DialogType.TWEET_EDITOR_LEAVE);
confirmDialog.show(ConfirmDialog.TWEET_EDITOR_LEAVE);
} else {
finish();
}

View File

@ -64,7 +64,6 @@ import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Relation;
import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import java.text.NumberFormat;
@ -361,7 +360,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
profileAsync = new UserAction(this, UserAction.ACTION_FOLLOW, user.getId());
profileAsync.execute();
} else {
confirmDialog.show(DialogType.PROFILE_UNFOLLOW);
confirmDialog.show(ConfirmDialog.PROFILE_UNFOLLOW);
}
}
}
@ -372,7 +371,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
profileAsync = new UserAction(this, UserAction.ACTION_UNMUTE, user.getId());
profileAsync.execute();
} else {
confirmDialog.show(DialogType.PROFILE_MUTE);
confirmDialog.show(ConfirmDialog.PROFILE_MUTE);
}
}
}
@ -383,7 +382,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
profileAsync = new UserAction(this, UserAction.ACTION_UNBLOCK, user.getId());
profileAsync.execute();
} else {
confirmDialog.show(DialogType.PROFILE_BLOCK);
confirmDialog.show(ConfirmDialog.PROFILE_BLOCK);
}
}
}
@ -543,20 +542,20 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
if (user != null) {
// confirmed unfollowing user
if (type == DialogType.PROFILE_UNFOLLOW) {
if (type == ConfirmDialog.PROFILE_UNFOLLOW) {
profileAsync = new UserAction(this, UserAction.ACTION_UNFOLLOW, user.getId());
profileAsync.execute();
}
// confirmed blocking user
else if (type == DialogType.PROFILE_BLOCK) {
else if (type == ConfirmDialog.PROFILE_BLOCK) {
profileAsync = new UserAction(this, UserAction.ACTION_BLOCK, user.getId());
profileAsync.execute();
}
// confirmed muting user
else if (type == DialogType.PROFILE_MUTE) {
else if (type == ConfirmDialog.PROFILE_MUTE) {
profileAsync = new UserAction(this, UserAction.ACTION_MUTE, user.getId());
profileAsync.execute();
}

View File

@ -34,7 +34,6 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.UserList;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import java.util.regex.Pattern;
@ -224,12 +223,12 @@ public class UserlistActivity extends AppCompatActivity implements OnTabSelected
}
// delete user list
else if (item.getItemId() == R.id.menu_delete_list) {
confirmDialog.show(DialogType.LIST_DELETE);
confirmDialog.show(ConfirmDialog.LIST_DELETE);
}
// follow user list
else if (item.getItemId() == R.id.menu_follow_list) {
if (userList.isFollowing()) {
confirmDialog.show(DialogType.LIST_UNFOLLOW);
confirmDialog.show(ConfirmDialog.LIST_UNFOLLOW);
} else {
listLoaderTask = new ListAction(this, userList.getId(), ListAction.FOLLOW);
listLoaderTask.execute();
@ -276,16 +275,16 @@ public class UserlistActivity extends AppCompatActivity implements OnTabSelected
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
// delete user list
if (type == DialogType.LIST_DELETE) {
if (type == ConfirmDialog.LIST_DELETE) {
if (userList != null) {
listLoaderTask = new ListAction(this, userList.getId(), ListAction.DELETE);
listLoaderTask.execute();
}
}
// unfollow user list
else if (type == DialogType.LIST_UNFOLLOW) {
else if (type == ConfirmDialog.LIST_UNFOLLOW) {
if (userList != null) {
listLoaderTask = new ListAction(this, userList.getId(), ListAction.UNFOLLOW);
listLoaderTask.execute();

View File

@ -25,7 +25,6 @@ import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.model.UserList;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog;
import org.nuclearfog.twidda.ui.dialogs.ProgressDialog.OnProgressStopListener;
@ -119,7 +118,7 @@ public class UserlistEditor extends AppCompatActivity implements OnClickListener
} else if (title.isEmpty() && descr.isEmpty()) {
super.onBackPressed();
} else {
confirmDialog.show(DialogType.LIST_EDITOR_LEAVE);
confirmDialog.show(ConfirmDialog.LIST_EDITOR_LEAVE);
}
}
@ -150,13 +149,13 @@ public class UserlistEditor extends AppCompatActivity implements OnClickListener
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
public void onConfirm(int type, boolean rememberChoice) {
// retry updating list
if (type == DialogType.LIST_EDITOR_ERROR) {
if (type == ConfirmDialog.LIST_EDITOR_ERROR) {
updateList();
}
// leave editor
else if (type == DialogType.LIST_EDITOR_LEAVE) {
else if (type == ConfirmDialog.LIST_EDITOR_LEAVE) {
finish();
}
}
@ -185,8 +184,7 @@ public class UserlistEditor extends AppCompatActivity implements OnClickListener
*/
public void onError(@Nullable ErrorHandler.TwitterError err) {
String message = ErrorHandler.getErrorMessage(this, err);
confirmDialog.setMessage(message);
confirmDialog.show(DialogType.LIST_EDITOR_ERROR);
confirmDialog.show(ConfirmDialog.LIST_EDITOR_ERROR, message);
loadingCircle.dismiss();
}

View File

@ -41,8 +41,7 @@ public class UsersActivity extends AppCompatActivity implements OnTabSelectedLis
/**
* type of users to get from twitter
* {@link #USERLIST_FRIENDS}, {@link #USERLIST_FOLLOWER}, {@link #USERLIST_RETWEETS},
* {@link #USERLIST_FAVORIT}, {@link #USERLIST_EXCLUDED_USERS} or {@link #USERLIST_REQUESTS},
* {@link #USERLIST_FRIENDS,#USERLIST_FOLLOWER,#USERLIST_RETWEETS,#USERLIST_FAVORIT,#USERLIST_EXCLUDED_USERS,#USERLIST_REQUESTS}
*/
public static final String KEY_USERDETAIL_MODE = "userlist_mode";

View File

@ -46,7 +46,6 @@ import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
/**
@ -341,7 +340,7 @@ public class VideoViewer extends MediaActivity implements OnSeekBarChangeListene
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
if (what == MEDIA_ERROR_UNKNOWN) {
confirmDialog.show(DialogType.VIDEO_ERROR);
confirmDialog.show(ConfirmDialog.VIDEO_ERROR);
return true;
}
return false;
@ -376,8 +375,8 @@ public class VideoViewer extends MediaActivity implements OnSeekBarChangeListene
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
if (type == DialogType.VIDEO_ERROR) {
public void onConfirm(int type, boolean rememberChoice) {
if (type == ConfirmDialog.VIDEO_ERROR) {
Uri link = getIntent().getParcelableExtra(VIDEO_URI);
if (link != null) {
// open link in a browser

View File

@ -9,6 +9,7 @@ import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.R;
@ -16,39 +17,123 @@ import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.database.GlobalSettings;
/**
* this dialog is to confirm for user action
* Custom alert dialog class to show error and warning messages to user
* and to ask to confirm actions
*
* @author nuclearfog
*/
public class ConfirmDialog extends Dialog implements OnClickListener {
/**
* types of dialogs, every dialog has its own message and title
* setup a proxy error dialog
*/
public enum DialogType {
WRONG_PROXY,
DELETE_APP_DATA,
APP_LOG_OUT,
REMOVE_ACCOUNT,
PROXY_CONFIRM,
VIDEO_ERROR,
TWEET_DELETE,
TWEET_EDITOR_LEAVE,
TWEET_EDITOR_ERROR,
MESSAGE_DELETE,
MESSAGE_EDITOR_LEAVE,
MESSAGE_EDITOR_ERROR,
PROFILE_EDITOR_LEAVE,
PROFILE_EDITOR_ERROR,
PROFILE_UNFOLLOW,
PROFILE_BLOCK,
PROFILE_MUTE,
LIST_REMOVE_USER,
LIST_UNFOLLOW,
LIST_DELETE,
LIST_EDITOR_LEAVE,
LIST_EDITOR_ERROR
}
public static final int WRONG_PROXY = 601;
/**
* show "delete app data" dialog
*/
public static final int DELETE_APP_DATA = 602;
/**
* show "log out" dialog
*/
public static final int APP_LOG_OUT = 603;
/**
* show "remove account" dialog
*/
public static final int REMOVE_ACCOUNT = 604;
/**
* show "proxy bypass" dialog
*/
public static final int PROXY_CONFIRM = 605;
/**
* show "video error" dialog
*/
public static final int VIDEO_ERROR = 606;
/**
* show "delete Tweet?" dialog
*/
public static final int TWEET_DELETE = 607;
/**
* show "discard tweet" dialog
*/
public static final int TWEET_EDITOR_LEAVE = 608;
/**
* show "Tweet create error" dialog
*/
public static final int TWEET_EDITOR_ERROR = 609;
/**
* show "delete directmessage" dialog
*/
public static final int MESSAGE_DELETE = 610;
/**
* show "discard directmessage" dialog
*/
public static final int MESSAGE_EDITOR_LEAVE = 611;
/**
* show "directmessage upload" error
*/
public static final int MESSAGE_EDITOR_ERROR = 612;
/**
* show "discard profile changes" dialog
*/
public static final int PROFILE_EDITOR_LEAVE = 613;
/**
* show "error profile update" dialog
*/
public static final int PROFILE_EDITOR_ERROR = 614;
/**
* show "unfollow user" dialog
*/
public static final int PROFILE_UNFOLLOW = 615;
/**
* show "block user" dialog
*/
public static final int PROFILE_BLOCK = 616;
/**
* show "mute user" dialog
*/
public static final int PROFILE_MUTE = 617;
/**
* show "remove user from list" dialog
*/
public static final int LIST_REMOVE_USER = 618;
/**
* show "unfollow userlist" dialog
*/
public static final int LIST_UNFOLLOW = 619;
/**
* show "delete userlsit" dialog
*/
public static final int LIST_DELETE = 620;
/**
* show "discard changes" dialog
*/
public static final int LIST_EDITOR_LEAVE = 621;
/**
* show "update userlist error" dialog
*/
public static final int LIST_EDITOR_ERROR = 622;
private TextView title, message, confirmDescr;
private CompoundButton confirmCheck;
@ -83,61 +168,73 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
*
* @param type Type of dialog to show
*/
public void show(DialogType type) {
public void show(int type) {
show(type, "");
}
/**
* creates an alert dialog
*
* @param type Type of dialog to show
* @param messageTxt override default message text
*/
public void show(int type, @NonNull String messageTxt) {
if (isShowing())
return;
// attach type to the view
confirm.setTag(type);
// default values
// default visibility values
int titleVis = View.GONE;
int titleTxt = R.string.info_error;
int messageTxt = R.string.confirm_unknown_error;
int confirmTxt = android.R.string.ok;
int confirmIcon = R.drawable.check;
int confirmVis = View.INVISIBLE;
int cancelTxt = android.R.string.cancel;
int cancelIcon = R.drawable.cross;
int cancelVis = View.VISIBLE;
// default resource values
int titleRes = R.string.info_error;
int messageRes = R.string.confirm_unknown_error;
int confirmRes = android.R.string.ok;
int confirmIconRes = R.drawable.check;
int cancelRes = android.R.string.cancel;
int cancelIconRes = R.drawable.cross;
switch (type) {
case MESSAGE_DELETE:
messageTxt = R.string.confirm_delete_message;
messageRes = R.string.confirm_delete_message;
break;
case WRONG_PROXY:
titleVis = View.VISIBLE;
messageTxt = R.string.error_wrong_connection_settings;
messageRes = R.string.error_wrong_connection_settings;
break;
case DELETE_APP_DATA:
messageTxt = R.string.confirm_delete_database;
messageRes = R.string.confirm_delete_database;
break;
case APP_LOG_OUT:
messageTxt = R.string.confirm_log_lout;
messageRes = R.string.confirm_log_lout;
break;
case VIDEO_ERROR:
titleVis = View.VISIBLE;
messageTxt = R.string.error_cant_load_video;
confirmIcon = 0;
confirmTxt = R.string.confirm_open_link;
messageRes = R.string.error_cant_load_video;
confirmIconRes = 0;
confirmRes = R.string.confirm_open_link;
cancelVis = View.GONE;
break;
case LIST_EDITOR_LEAVE:
case PROFILE_EDITOR_LEAVE:
messageTxt = R.string.confirm_discard;
messageRes = R.string.confirm_discard;
break;
case TWEET_EDITOR_LEAVE:
messageTxt = R.string.confirm_cancel_tweet;
messageRes = R.string.confirm_cancel_tweet;
break;
case MESSAGE_EDITOR_LEAVE:
messageTxt = R.string.confirm_cancel_message;
messageRes = R.string.confirm_cancel_message;
break;
case LIST_EDITOR_ERROR:
@ -145,62 +242,66 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
case TWEET_EDITOR_ERROR:
case PROFILE_EDITOR_ERROR:
titleVis = View.VISIBLE;
messageTxt = R.string.error_connection_failed;
confirmTxt = R.string.confirm_retry_button;
messageRes = R.string.error_connection_failed;
confirmRes = R.string.confirm_retry_button;
break;
case TWEET_DELETE:
messageTxt = R.string.confirm_delete_tweet;
messageRes = R.string.confirm_delete_tweet;
break;
case PROFILE_UNFOLLOW:
messageTxt = R.string.confirm_unfollow;
messageRes = R.string.confirm_unfollow;
break;
case PROFILE_BLOCK:
messageTxt = R.string.confirm_block;
messageRes = R.string.confirm_block;
break;
case PROFILE_MUTE:
messageTxt = R.string.confirm_mute;
messageRes = R.string.confirm_mute;
break;
case LIST_REMOVE_USER:
messageTxt = R.string.confirm_remove_user_from_list;
messageRes = R.string.confirm_remove_user_from_list;
break;
case LIST_UNFOLLOW:
messageTxt = R.string.confirm_unfollow_list;
messageRes = R.string.confirm_unfollow_list;
break;
case LIST_DELETE:
messageTxt = R.string.confirm_delete_list;
messageRes = R.string.confirm_delete_list;
break;
case REMOVE_ACCOUNT:
messageTxt = R.string.confirm_remove_account;
messageRes = R.string.confirm_remove_account;
break;
case PROXY_CONFIRM:
confirmVis = View.VISIBLE;
titleVis = View.VISIBLE;
titleTxt = R.string.dialog_confirm_warning;
messageTxt = R.string.dialog_warning_videoview;
titleRes = R.string.dialog_confirm_warning;
messageRes = R.string.dialog_warning_videoview;
break;
}
title.setVisibility(titleVis);
title.setText(titleTxt);
message.setText(messageTxt);
title.setText(titleRes);
cancel.setVisibility(cancelVis);
cancel.setText(cancelTxt);
cancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, 0, 0, 0);
cancel.setText(cancelRes);
cancel.setCompoundDrawablesWithIntrinsicBounds(cancelIconRes, 0, 0, 0);
confirmCheck.setVisibility(confirmVis);
confirmDescr.setVisibility(confirmVis);
confirm.setText(confirmTxt);
confirm.setCompoundDrawablesWithIntrinsicBounds(confirmIcon, 0, 0, 0);
confirm.setText(confirmRes);
confirm.setCompoundDrawablesWithIntrinsicBounds(confirmIconRes, 0, 0, 0);
if (messageTxt.isEmpty())
message.setText(messageRes);
else
message.setText(messageTxt);
super.show();
}
@ -210,8 +311,8 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
public void onClick(View v) {
if (v.getId() == R.id.confirm_yes) {
Object tag = v.getTag();
if (listener != null && tag instanceof DialogType) {
DialogType type = (DialogType) tag;
if (listener != null && tag instanceof Integer) {
int type = (int) tag;
boolean remember = confirmCheck.getVisibility() == View.VISIBLE && confirmCheck.isChecked();
listener.onConfirm(type, remember);
}
@ -228,15 +329,6 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
this.listener = listener;
}
/**
* set message text
*
* @param message message text
*/
public void setMessage(String message) {
this.message.setText(message);
}
/**
* Alert dialog listener
*/
@ -244,10 +336,9 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
/**
* called when the positive button was clicked
*
* @param type type of dialog
* @param type type of dialog
* @param rememberChoice true if choice should be remembered
*/
void onConfirm(DialogType type, boolean rememberChoice);
void onConfirm(int type, boolean rememberChoice);
}
}

View File

@ -1,7 +1,6 @@
package org.nuclearfog.twidda.ui.fragments;
import static android.os.AsyncTask.Status.RUNNING;
import static org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import android.os.Bundle;
import android.view.View;
@ -101,14 +100,14 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
public void onAccountRemove(Account account) {
if (!dialog.isShowing()) {
selection = account;
dialog.show(DialogType.REMOVE_ACCOUNT);
dialog.show(ConfirmDialog.REMOVE_ACCOUNT);
}
}
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
if (type == DialogType.REMOVE_ACCOUNT) {
public void onConfirm(int type, boolean rememberChoice) {
if (type == ConfirmDialog.REMOVE_ACCOUNT) {
loginTask = new AccountLoader(this);
loginTask.execute(selection);
}

View File

@ -32,7 +32,6 @@ import org.nuclearfog.twidda.ui.activities.SearchActivity;
import org.nuclearfog.twidda.ui.activities.TweetActivity;
import org.nuclearfog.twidda.ui.activities.UserProfile;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
/**
@ -130,7 +129,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
@Override
public void onClick(DirectMessage message, Action action) {
public void onClick(DirectMessage message, int action) {
if (!isRefreshing()) {
switch (action) {
case ANSWER:
@ -142,7 +141,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
case DELETE:
if (!confirmDialog.isShowing() && messageTask != null && messageTask.getStatus() != RUNNING) {
deleteId = message.getId();
confirmDialog.show(DialogType.MESSAGE_DELETE);
confirmDialog.show(ConfirmDialog.MESSAGE_DELETE);
}
break;
@ -176,8 +175,8 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
if (type == DialogType.MESSAGE_DELETE) {
public void onConfirm(int type, boolean rememberChoice) {
if (type == ConfirmDialog.MESSAGE_DELETE) {
if (messageTask != null && messageTask.getStatus() != RUNNING) {
messageTask = new MessageLoader(this, MessageLoader.DEL, null, deleteId);
messageTask.execute();

View File

@ -28,8 +28,7 @@ public class TweetFragment extends ListFragment implements TweetClickListener {
/**
* Key to define what type of tweets should be loaded
* possible values are {@link #TWEET_FRAG_HOME}, {@link #TWEET_FRAG_MENT}, {@link #TWEET_FRAG_TWEETS}, {@link #TWEET_FRAG_FAVORS}
* {@link #TWEET_FRAG_ANSWER}, {@link #TWEET_FRAG_SEARCH}, {@link #TWEET_FRAG_LIST}
* possible values are {@link #TWEET_FRAG_HOME,#TWEET_FRAG_MENT,#TWEET_FRAG_TWEETS,#TWEET_FRAG_FAVORS,#TWEET_FRAG_ANSWER,#TWEET_FRAG_SEARCH,#TWEET_FRAG_LIST}
*/
public static final String KEY_FRAG_TWEET_MODE = "tweet_mode";

View File

@ -24,7 +24,6 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.ui.activities.UserProfile;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.DialogType;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
/**
@ -36,10 +35,10 @@ public class UserFragment extends ListFragment implements UserClickListener, OnC
/**
* key to set the type of user list to show
* possible value types are {@link #USER_FRAG_FOLLOWER}, {@link #USER_FRAG_FOLLOWING}, {@link #USER_FRAG_RETWEET},
* {@link #USER_FRAG_FAVORIT}, {@link #USER_FRAG_FAVORIT}, {@link #USER_FRAG_SEARCH}, {@link #USER_FRAG_LIST_SUBSCRIBER},
* {@link #USER_FRAG_LIST_MEMBERS}, {@link #USER_FRAG_BLOCKED_USERS}, {@link #USER_FRAG_MUTED_USERS},
* {@link #USER_FRAG_FOLLOW_INCOMING} and {@link #USER_FRAG_FOLLOW_OUTGOING}
* possible value types are
* {@link #USER_FRAG_FOLLOWER,#USER_FRAG_FOLLOWING,#USER_FRAG_RETWEET,#USER_FRAG_FAVORIT},
* {@link #USER_FRAG_SEARCH,#USER_FRAG_LIST_SUBSCRIBER,#USER_FRAG_LIST_MEMBERS,#USER_FRAG_BLOCKED_USERS},
* {@link #USER_FRAG_MUTED_USERS,#USER_FRAG_FOLLOW_INCOMING,#USER_FRAG_FOLLOW_OUTGOING}
*/
public static final String KEY_FRAG_USER_MODE = "user_mode";
@ -244,14 +243,14 @@ public class UserFragment extends ListFragment implements UserClickListener, OnC
public void onDelete(String name) {
if (!confirmDialog.isShowing()) {
deleteUserName = name;
confirmDialog.show(DialogType.LIST_REMOVE_USER);
confirmDialog.show(ConfirmDialog.LIST_REMOVE_USER);
}
}
@Override
public void onConfirm(DialogType type, boolean rememberChoice) {
if (type == DialogType.LIST_REMOVE_USER) {
public void onConfirm(int type, boolean rememberChoice) {
if (type == ConfirmDialog.LIST_REMOVE_USER) {
if (listTask == null || listTask.getStatus() != RUNNING) {
listTask = new ListManager(requireContext(), id, ListManager.DEL_USER, deleteUserName, this);
listTask.execute();

View File

@ -44,7 +44,7 @@ public class UserListFragment extends ListFragment implements ListClickListener
/**
* key to define the type of the list
* {@link #LIST_USER_OWNS} or {@link #LIST_USER_SUBSCR_TO}
* {@link #LIST_USER_OWNS,#LIST_USER_SUBSCR_TO}
*/
public static final String KEY_FRAG_LIST_LIST_TYPE = "list_type";