Fix thumbs up/down

This commit is contained in:
Thomas 2020-06-29 17:59:36 +02:00
parent 689e16bf62
commit b1d1111142
3 changed files with 55 additions and 24 deletions

View File

@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "app.fedilab.fedilabtube"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"

View File

@ -10,6 +10,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
@ -38,6 +39,7 @@ import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -92,6 +94,7 @@ import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST;
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST_FOR_VIDEO;
import static app.fedilab.fedilabtube.helper.Helper.changeDrawableColor;
import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
@ -468,6 +471,16 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
int count = Integer.parseInt(peertube_like_count.getText().toString());
if( newState.compareTo("none") == 0) {
count--;
if( count - 1 < 0 ) {
count = 0;
}
}else{
count++;
}
peertube_like_count.setText(String.valueOf(count));
changeColor();
} else {
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
@ -478,6 +491,16 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
int count = Integer.parseInt(peertube_dislike_count.getText().toString());
if( newState.compareTo("none") == 0) {
count--;
if( count - 1 < 0 ) {
count = 0;
}
}else{
count++;
}
peertube_dislike_count.setText(String.valueOf(count));
changeColor();
} else {
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
@ -703,7 +726,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void initFullscreenDialog() {
@ -756,15 +778,32 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
}
private void changeColor() {
if (peertube.getMyRating() != null && peertube.getMyRating().equals("like")) {
changeDrawableColor(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24, R.color.positive_thumbs);
Drawable thumbUp = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24);
peertube_like_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbUp, null, null);
} else if (peertube.getMyRating() != null && peertube.getMyRating().equals("dislike")) {
changeDrawableColor(PeertubeActivity.this, R.drawable.ic_baseline_thumb_down_alt_24, R.color.negative_thumbs);
Drawable thumbDown = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_down_alt_24);
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
int color = getAttColor(this, android.R.attr.colorControlNormal);
if( thumbUp != null ) {
thumbUp.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
DrawableCompat.setTint(thumbUp, color);
}
if( thumbDown != null ) {
thumbDown.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
DrawableCompat.setTint(thumbDown, color);
}
if (peertube.getMyRating() != null && peertube.getMyRating().compareTo("like") == 0) {
if( thumbUp != null ) {
thumbUp.setColorFilter(getResources().getColor(R.color.positive_thumbs), PorterDuff.Mode.SRC_ATOP);
DrawableCompat.setTint(thumbUp, getResources().getColor(R.color.positive_thumbs));
}
}else if (peertube.getMyRating() != null && peertube.getMyRating().compareTo("dislike") == 0) {
if( thumbDown != null ) {
thumbDown.setColorFilter(getResources().getColor(R.color.negative_thumbs), PorterDuff.Mode.SRC_ATOP);
DrawableCompat.setTint(thumbDown, getResources().getColor(R.color.negative_thumbs));
}
}
peertube_like_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbUp, null, null);
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
}
@Override

View File

@ -64,8 +64,6 @@ public class Helper {
public static final int DEFAULT_VIDEO_CACHE_MB = 100;
public static final String TAG = "mastodon_etalab";
public static final String CLIENT_NAME_VALUE = "Fedilab";
public static final String OAUTH_SCOPES = "read write follow";
public static final String OAUTH_SCOPES_ADMIN = "read write follow admin:read admin:write admin";
public static final String OAUTH_SCOPES_PEERTUBE = "user";
public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token";
public static final Pattern urlPattern = Pattern.compile(
@ -73,7 +71,6 @@ public class Helper {
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)");
public static final String SET_ALLOW_STREAM = "set_allow_stream";
public static final String SET_CUSTOM_USER_AGENT = "set_custom_user_agent";
public static final String SET_VIDEO_CACHE = "set_video_cache";
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0";
@ -90,7 +87,6 @@ public class Helper {
public static final String PREF_IS_ADMINISTRATOR = "is_administrator";
public static final String PREF_INSTANCE = "instance";
public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob";
public static final String REDIRECT_CONTENT_WEB = "mastalab://backtomastalab";
public static final int EXTERNAL_STORAGE_REQUEST_CODE = 84;
public static final String SET_VIDEOS_PER_PAGE = "set_videos_per_page";
public static final String VIDEO_ID = "video_id_update";
@ -99,22 +95,14 @@ public class Helper {
public static final String ID = "id";
public static final String CLIENT_ID = "client_id";
public static final String CLIENT_SECRET = "client_secret";
public static final String REDIRECT_URI = "redirect_uri";
public static final String REDIRECT_URIS = "redirect_uris";
public static final String RESPONSE_TYPE = "response_type";
public static final String SCOPE = "scope";
public static final String SCOPES = "scopes";
public static final String WEBSITE = "website";
public static final String SHOW_ACCOUNT_BOOSTS = "show_account_boosts";
public static final String SHOW_ACCOUNT_REPLIES = "show_account_replies";
public static final String WEBSITE_VALUE = "https://fedilab.app";
public static final String SHOW_BATTERY_SAVER_MESSAGE = "show_battery_saver_message";
public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id";
public static final int VIDEOS_PER_PAGE = 40;
public static final String SET_VIDEO_NSFW = "set_video_nsfw";
public static final String SET_EMBEDDED_BROWSER = "set_embedded_browser";
public static final String SET_CUSTOM_TABS = "set_custom_tabs";
public static final String SET_DISPLAY_CONFIRM = "set_display_confirm";
public static final String INTENT_ADD_UPLOADED_MEDIA = "intent_add_uploaded_media";
public static final String RECEIVE_ACTION = "receive_action";
public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation";
@ -534,8 +522,6 @@ public class Helper {
* @param url String download url
*/
public static void manageDownloads(final Context context, final String url) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
final DownloadManager.Request request;
try {
@ -564,6 +550,12 @@ public class Helper {
}
public static int getAttColor(Context context, int attColor) {
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(attColor, typedValue, true);
return ContextCompat.getColor(context, typedValue.resourceId);
}
/**
* change color of a drawable
*