diff --git a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java index b724661..b01e732 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java @@ -78,8 +78,6 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis setTitle(R.string.playlists); - - textviewNoAction = findViewById(R.id.no_action); mainLoader = findViewById(R.id.loader); RelativeLayout nextElementLoader = findViewById(R.id.loading_next_items); diff --git a/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java b/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java index c0359e2..588493b 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java @@ -1,5 +1,6 @@ package app.fedilab.fedilabtube; + import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; @@ -15,40 +16,73 @@ import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import org.jetbrains.annotations.NotNull; import org.json.JSONException; import org.json.JSONObject; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; +import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeNotificationsAsyncTask; import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask; +import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.HttpsConnection; import app.fedilab.fedilabtube.client.entities.Account; +import app.fedilab.fedilabtube.client.entities.PeertubeNotification; +import app.fedilab.fedilabtube.drawer.PeertubeNotificationsListAdapter; import app.fedilab.fedilabtube.helper.Helper; +import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeNotificationsInterface; import app.fedilab.fedilabtube.sqlite.AccountDAO; import app.fedilab.fedilabtube.sqlite.Sqlite; import es.dmoral.toasty.Toasty; -public class LoginActivity extends AppCompatActivity { +public class LoginActivity extends AppCompatActivity implements OnRetrievePeertubeNotificationsInterface { + //Peertube notification type + public static int NEW_VIDEO_FROM_SUBSCRIPTION = 1; + // public static int NEW_COMMENT_ON_MY_VIDEO = 2; + // public static int NEW_VIDEO_ABUSE_FOR_MODERATORS = 3; + public static int BLACKLIST_ON_MY_VIDEO = 4; + public static int UNBLACKLIST_ON_MY_VIDEO = 5; + public static int MY_VIDEO_PUBLISHED = 6; + public static int MY_VIDEO_IMPORT_SUCCESS = 7; + public static int MY_VIDEO_IMPORT_ERROR = 8; private static String client_id; private static String client_secret; + // public static int NEW_USER_REGISTRATION = 9; + //public static int NEW_FOLLOW = 10; + // public static int COMMENT_MENTION = 11; + LinearLayoutManager mLayoutManager; private EditText login_uid; private EditText login_passwd; private Button connectionButton; private String actionToken; - + private boolean flag_loading; + private PeertubeNotificationsListAdapter notificationsListAdapter; + private String max_id; + private List notifications; + private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; + private boolean firstLoad; + private SwipeRefreshLayout swipeRefreshLayout; + private boolean swiped; + private AsyncTask asyncTask; @Override protected void onCreate(Bundle savedInstanceState) { @@ -123,7 +157,51 @@ public class LoginActivity extends AppCompatActivity { Helper.logoutCurrentUser(LoginActivity.this, null); } + max_id = null; + firstLoad = true; + flag_loading = true; + notifications = new ArrayList<>(); + swiped = false; + swipeRefreshLayout = findViewById(R.id.swipeContainer); + RecyclerView lv_notifications = findViewById(R.id.lv_notifications); + mainLoader = findViewById(R.id.loader); + nextElementLoader = findViewById(R.id.loading_next_notifications); + textviewNoAction = findViewById(R.id.no_action); + mainLoader.setVisibility(View.VISIBLE); + nextElementLoader.setVisibility(View.GONE); + notificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications); + lv_notifications.setAdapter(notificationsListAdapter); + mLayoutManager = new LinearLayoutManager(LoginActivity.this); + lv_notifications.setLayoutManager(mLayoutManager); + lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() { + public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + int visibleItemCount = mLayoutManager.getChildCount(); + int totalItemCount = mLayoutManager.getItemCount(); + int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition(); + if (firstVisibleItem + visibleItemCount == totalItemCount) { + if (!flag_loading) { + flag_loading = true; + asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, max_id, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + nextElementLoader.setVisibility(View.VISIBLE); + } + } else { + nextElementLoader.setVisibility(View.GONE); + } + } + } + }); + + + swipeRefreshLayout.setOnRefreshListener(() -> { + max_id = null; + firstLoad = true; + flag_loading = true; + swiped = true; + asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, null, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }); + asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, max_id, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { connected.setVisibility(View.GONE); } @@ -257,5 +335,53 @@ public class LoginActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } + @Override + public void onDestroy() { + super.onDestroy(); + if (asyncTask != null && !asyncTask.isCancelled()) { + asyncTask.cancel(true); + } + } + + + @Override + public void onRetrievePeertubeNotifications(APIResponse apiResponse, Account account) { + mainLoader.setVisibility(View.GONE); + nextElementLoader.setVisibility(View.GONE); + if (apiResponse.getError() != null) { + Toasty.error(LoginActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); + flag_loading = false; + swipeRefreshLayout.setRefreshing(false); + swiped = false; + return; + } + + int previousPosition = notifications.size(); + max_id = apiResponse.getMax_id(); + List notifications = apiResponse.getPeertubeNotifications(); + if (!swiped && firstLoad && (notifications == null || notifications.size() == 0)) + textviewNoAction.setVisibility(View.VISIBLE); + else + textviewNoAction.setVisibility(View.GONE); + if (swiped) { + if (previousPosition > 0) { + this.notifications.subList(0, previousPosition).clear(); + notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition); + } + swiped = false; + } + + if (notifications != null && notifications.size() > 0) { + this.notifications.addAll(notifications); + notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size()); + } else { + if (firstLoad) + textviewNoAction.setVisibility(View.VISIBLE); + } + swipeRefreshLayout.setRefreshing(false); + firstLoad = false; + //The initial call comes from a classic tab refresh + flag_loading = (max_id == null); + } } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index db61d93..ba1a5ee 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -229,7 +229,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee initFullscreenDialog(); initFullscreenButton(); } - if( Helper.isLoggedIn(PeertubeActivity.this)) { + if (Helper.isLoggedIn(PeertubeActivity.this)) { new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST, null, null, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -316,7 +316,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - add_comment_read.setOnClickListener(v -> { if (isLoggedIn(PeertubeActivity.this)) { add_comment_read.setVisibility(View.GONE); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java index 43b259b..67a25a4 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java @@ -5,21 +5,15 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.Spinner; -import android.widget.TextView; import android.widget.Toast; -import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; @@ -81,21 +75,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR } if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); - assert inflater != null; - View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PeertubeEditUploadActivity.this), false); - actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); - ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); - TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); - toolbar_close.setOnClickListener(v -> finish()); - toolbar_title.setText(R.string.update_video); - } setContentView(R.layout.activity_peertube_edit); - - set_upload_submit = findViewById(R.id.set_upload_submit); Button set_upload_delete = findViewById(R.id.set_upload_delete); set_upload_privacy = findViewById(R.id.set_upload_privacy); @@ -127,6 +107,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR LinkedHashMap privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies()); LinkedHashMap languages = new LinkedHashMap<>(peertubeInformation.getLanguages()); LinkedHashMap translations = null; + if (peertubeInformation.getTranslations() != null) translations = new LinkedHashMap<>(peertubeInformation.getTranslations()); //Populate catgories @@ -169,13 +150,13 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR String[] languagesA = new String[languages.size()]; Iterator> itl = languages.entrySet().iterator(); i = 0; - while (it.hasNext()) { + while (itl.hasNext()) { Map.Entry pair = itl.next(); if (translations == null || translations.size() == 0 || !translations.containsKey(pair.getValue())) languagesA[i] = pair.getValue(); else languagesA[i] = translations.get(pair.getValue()); - it.remove(); + itl.remove(); i++; } ArrayAdapter adapterLanguages = new ArrayAdapter<>(PeertubeEditUploadActivity.this, @@ -196,6 +177,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR it.remove(); i++; } + ArrayAdapter adapterPrivacies = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, privaciesA); set_upload_privacy.setAdapter(adapterPrivacies); @@ -206,7 +188,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR channels = new LinkedHashMap<>(); - } @@ -237,7 +218,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR privacyToSend = peertube.getPrivacy(); categoryToSend = peertube.getCategory(); - if (languageToSend == null) { LinkedHashMap languages = new LinkedHashMap<>(peertubeInformation.getLanguages()); Map.Entry entryString = languages.entrySet().iterator().next(); @@ -266,7 +246,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR } String language = null; - if (languageToSend != null) { Map.Entry entryString = languageToSend.entrySet().iterator().next(); language = entryString.getValue(); @@ -289,7 +268,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR Map.Entry entryInt = categoryToSend.entrySet().iterator().next(); category = entryInt.getValue(); } - channel = peertube.getChannel(); String title = peertube.getName(); boolean commentEnabled = peertube.isCommentsEnabled(); @@ -301,7 +279,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR p_video_title.setText(title); p_video_description.setText(peertube.getDescription()); - LinkedHashMap categories = new LinkedHashMap<>(peertubeInformation.getCategories()); LinkedHashMap licences = new LinkedHashMap<>(peertubeInformation.getLicences()); LinkedHashMap privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies()); @@ -352,7 +329,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR categoryPosition++; } } - //Manage privacies set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override @@ -523,7 +499,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); return; } - //Populate channels List accounts = apiResponse.getAccounts(); String[] channelName = new String[accounts.size()]; @@ -536,7 +511,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR ArrayAdapter adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, channelName); set_upload_channel.setAdapter(adapterChannel); - int channelPosition = 0; if (channels.containsKey(channel.getUsername())) { LinkedHashMap channelsIterator = new LinkedHashMap<>(channels); @@ -553,7 +527,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR } } set_upload_channel.setSelection(channelPosition); - set_upload_submit.setEnabled(true); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeSingleAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeSingleAsyncTask.java index 2a2d0de..2b85bd5 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeSingleAsyncTask.java +++ b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeSingleAsyncTask.java @@ -12,10 +12,9 @@ import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface; -public class RetrievePeertubeSingleAsyncTask extends AsyncTask { +public class RetrievePeertubeSingleAsyncTask extends AsyncTask { - private APIResponse apiResponse; private String videoId; private OnRetrievePeertubeInterface listener; private WeakReference contextReference; @@ -31,21 +30,21 @@ public class RetrievePeertubeSingleAsyncTask extends AsyncTask @Override - protected Void doInBackground(Void... params) { + protected APIResponse doInBackground(Void... params) { PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get()); SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); - apiResponse = peertubeAPI.getSinglePeertube(this.instanceName, videoId, token); + APIResponse apiResponse = peertubeAPI.getSinglePeertube(this.instanceName, videoId, token); if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) { String rate = new PeertubeAPI(this.contextReference.get()).getRating(videoId); if (rate != null) apiResponse.getPeertubes().get(0).setMyRating(rate); } - return null; + return apiResponse; } @Override - protected void onPostExecute(Void result) { + protected void onPostExecute(APIResponse apiResponse) { listener.onRetrievePeertube(apiResponse); } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java index 11a14e2..ab2d5ea 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java @@ -684,7 +684,7 @@ public class PeertubeAPI { if (PeertubeInformation.langueMapped.containsKey(Locale.getDefault().getLanguage())) lang = PeertubeInformation.langueMapped.get(Locale.getDefault().getLanguage()); - if (lang != null && !lang.startsWith("en")) { + if (lang != null) { response = new HttpsConnection(context).get(String.format("https://" + instance + "/client/locales/%s/server.json", lang), 60, null, null); JSONObject translations = new JSONObject(response); LinkedHashMap _translations = new LinkedHashMap<>(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java index 1972796..ea810c8 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java @@ -20,6 +20,7 @@ import com.bumptech.glide.Glide; import java.util.List; import app.fedilab.fedilabtube.PeertubeActivity; +import app.fedilab.fedilabtube.PeertubeEditUploadActivity; import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.ShowAccountActivity; import app.fedilab.fedilabtube.client.APIResponse; @@ -64,7 +65,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter { - Intent intent = new Intent(context, PeertubeActivity.class); - Bundle b = new Bundle(); - b.putString("video_id", peertube.getUuid()); - intent.putExtras(b); - context.startActivity(intent); - }); + if (!ownVideos) { + holder.bottom_container.setOnClickListener(v -> { + Intent intent = new Intent(context, PeertubeActivity.class); + Bundle b = new Bundle(); + b.putString("video_id", peertube.getUuid()); + intent.putExtras(b); + context.startActivity(intent); + }); + } else { + holder.bottom_container.setOnClickListener(v -> { + Intent intent = new Intent(context, PeertubeEditUploadActivity.class); + Bundle b = new Bundle(); + b.putString("video_id", peertube.getUuid()); + intent.putExtras(b); + context.startActivity(intent); + }); + } holder.peertube_video_image.setOnClickListener(v -> { Intent intent = new Intent(context, PeertubeActivity.class); Bundle b = new Bundle(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeNotificationsListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeNotificationsListAdapter.java new file mode 100644 index 0000000..f764fc9 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeNotificationsListAdapter.java @@ -0,0 +1,180 @@ +package app.fedilab.fedilabtube.drawer; + +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.text.Html; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +import app.fedilab.fedilabtube.LoginActivity; +import app.fedilab.fedilabtube.PeertubeActivity; +import app.fedilab.fedilabtube.R; +import app.fedilab.fedilabtube.ShowAccountActivity; +import app.fedilab.fedilabtube.client.entities.PeertubeAccountNotification; +import app.fedilab.fedilabtube.client.entities.PeertubeNotification; +import app.fedilab.fedilabtube.client.entities.PeertubeVideoNotification; +import app.fedilab.fedilabtube.helper.Helper; + + +public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter { + + private Context context; + private List notifications; + + public PeertubeNotificationsListAdapter(List notifications) { + this.notifications = notifications; + } + + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + context = parent.getContext(); + LayoutInflater layoutInflater = LayoutInflater.from(this.context); + return new ViewHolder(layoutInflater.inflate(R.layout.drawer_peertube_notification, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { + + ViewHolder holder = (ViewHolder) viewHolder; + PeertubeNotification notification = notifications.get(position); + //Follow Notification + PeertubeAccountNotification accountAction = null; + PeertubeVideoNotification videoAction; + if (notification.getPeertubeActorFollow() != null) { + String profileUrl = "https://" + Helper.getLiveInstance(context) + notification.getPeertubeActorFollow().getFollower().getAvatar(); + Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp); + accountAction = notification.getPeertubeActorFollow().getFollower(); + String type = notification.getPeertubeActorFollow().getFollowing().getType(); + String message; + if (type != null && type.equals("account")) { + message = context.getString(R.string.peertube_follow_channel, notification.getPeertubeActorFollow().getFollower().getDisplayName(), notification.getPeertubeActorFollow().getFollowing().getDisplayName()); + } else { + message = context.getString(R.string.peertube_follow_account, accountAction.getDisplayName()); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + holder.peertube_notif_message.setText(Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY)); + else + holder.peertube_notif_message.setText(Html.fromHtml(message)); + PeertubeAccountNotification finalAccountAction1 = accountAction; + holder.peertube_notif_pp.setOnClickListener(v -> { + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putBoolean("peertubeaccount", true); + b.putString("accountId", finalAccountAction1.getName()); + intent.putExtras(b); + context.startActivity(intent); + }); + } else if (notification.getPeertubeComment() != null) { //Comment Notification + String profileUrl = "https://" + Helper.getLiveInstance(context) + notification.getPeertubeComment().getPeertubeAccountNotification().getAvatar(); + Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp); + accountAction = notification.getPeertubeComment().getPeertubeAccountNotification(); + videoAction = notification.getPeertubeComment().getPeertubeVideoNotification(); + String message = context.getString(R.string.peertube_comment_on_video, accountAction.getDisplayName(), videoAction.getName()); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + holder.peertube_notif_message.setText(Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY)); + else + holder.peertube_notif_message.setText(Html.fromHtml(message)); + PeertubeVideoNotification finalVideoAction1 = videoAction; + holder.peertube_notif_message.setOnClickListener(v -> { + Intent intent = new Intent(context, PeertubeActivity.class); + Bundle b = new Bundle(); + b.putString("peertube_instance", Helper.getLiveInstance(context)); + b.putString("video_id", finalVideoAction1.getUuid()); + intent.putExtras(b); + context.startActivity(intent); + }); + } else {//Other Notifications + if (notification.getPeertubeVideoNotification() != null && notification.getPeertubeVideoNotification().getPeertubeAccountNotification() != null) { + String profileUrl = "https://" + Helper.getLiveInstance(context) + notification.getPeertubeVideoNotification().getPeertubeAccountNotification().getAvatar(); + Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp); + accountAction = notification.getPeertubeVideoNotification().getPeertubeAccountNotification(); + videoAction = notification.getPeertubeVideoNotification(); + String message = ""; + if (notification.getType() == LoginActivity.MY_VIDEO_PUBLISHED) { + message = context.getString(R.string.peertube_video_published, videoAction.getName()); + } else if (notification.getType() == LoginActivity.MY_VIDEO_IMPORT_ERROR) { + message = context.getString(R.string.peertube_video_import_error, videoAction.getName()); + } else if (notification.getType() == LoginActivity.MY_VIDEO_IMPORT_SUCCESS) { + message = context.getString(R.string.peertube_video_import_success, videoAction.getName()); + } else if (notification.getType() == LoginActivity.NEW_VIDEO_FROM_SUBSCRIPTION) { + message = context.getString(R.string.peertube_video_from_subscription, accountAction.getDisplayName(), videoAction.getName()); + } else if (notification.getType() == LoginActivity.BLACKLIST_ON_MY_VIDEO) { + message = context.getString(R.string.peertube_video_blacklist, videoAction.getName()); + } else if (notification.getType() == LoginActivity.UNBLACKLIST_ON_MY_VIDEO) { + message = context.getString(R.string.peertube_video_unblacklist, videoAction.getName()); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + holder.peertube_notif_message.setText(Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY)); + else + holder.peertube_notif_message.setText(Html.fromHtml(message)); + PeertubeVideoNotification finalVideoAction = videoAction; + holder.peertube_notif_message.setOnClickListener(v -> { + Intent intent = new Intent(context, PeertubeActivity.class); + Bundle b = new Bundle(); + b.putString("peertube_instance", Helper.getLiveInstance(context)); + b.putString("video_id", finalVideoAction.getUuid()); + intent.putExtras(b); + context.startActivity(intent); + }); + } + } + holder.peertube_notif_date.setText(Helper.dateDiff(context, notification.getCreatedAt())); + PeertubeAccountNotification finalAccountAction = accountAction; + holder.peertube_notif_pp.setOnClickListener(v -> { + if (finalAccountAction != null) { + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putBoolean("peertubeaccount", true); + b.putString("accountId", finalAccountAction.getName() + "@" + finalAccountAction.getHost()); + intent.putExtras(b); + context.startActivity(intent); + } + }); + } + + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public int getItemCount() { + return notifications.size(); + } + + + static class ViewHolder extends RecyclerView.ViewHolder { + + ImageView peertube_notif_pp; + TextView peertube_notif_message, peertube_notif_date; + RelativeLayout main_container_trans; + + public ViewHolder(View itemView) { + super(itemView); + peertube_notif_pp = itemView.findViewById(R.id.peertube_notif_pp); + peertube_notif_message = itemView.findViewById(R.id.peertube_notif_message); + peertube_notif_date = itemView.findViewById(R.id.peertube_notif_date); + main_container_trans = itemView.findViewById(R.id.container_trans); + } + + public View getView() { + return itemView; + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java index 5a4f538..2b6b845 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java @@ -75,7 +75,7 @@ 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_CUSTOM_USER_AGENT = "set_custom_user_agent"; + public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id"; public static final String SET_VIDEO_CACHE = "set_video_cache"; //Proxy public static final String SET_PROXY_ENABLED = "set_proxy_enabled"; @@ -421,10 +421,37 @@ public class Helper { } catch (Exception ignored) { } } - } + public static void loadGiF(final Context context, String url, final ImageView imageView) { + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + + if (url.startsWith("/")) { + url = Helper.getLiveInstance(context) + url; + } + if (!url.startsWith("http")) { + url = "https://" + url; + } + try { + Glide.with(imageView.getContext()) + .load(url) + .thumbnail(0.1f) + .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))) + .into(imageView); + } catch (Exception e) { + try { + Glide.with(imageView.getContext()) + .asDrawable() + .load(R.drawable.missing_peertube) + .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))) + .into(imageView); + + } catch (Exception ignored) { + } + } + } + /** * Manage URLs to open (built-in or external app) * diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index dce906f..e7e6d0a 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -1,224 +1,291 @@ - - + android:layout_height="match_parent" + android:visibility="gone" + android:orientation="vertical"> - + + + + + + + + + + android:paddingStart="50dp" + android:paddingEnd="50dp"> - + + + + + + + + + + + + + +