Fixed view media fragment behaviour, reblogs/favs of reblogs

main
Eugen Rochko 8 years ago
parent bc46afd801
commit ce82a81f0e
  1. 28
      app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java
  2. 41
      app/src/main/java/com/keylesspalace/tusky/SFragment.java
  3. 31
      app/src/main/java/com/keylesspalace/tusky/ViewMediaFragment.java
  4. 7
      app/src/main/res/layout/fragment_view_media.xml
  5. 5
      app/src/main/res/values/styles.xml

@ -166,17 +166,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
builder.setLargeIcon(bitmap); builder.setLargeIcon(bitmap);
if (preferences.getBoolean("notificationAlertSound", true)) { setupPreferences(preferences, builder);
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
}
if (preferences.getBoolean("notificationStyleVibrate", false)) {
builder.setVibrate(new long[] { 500, 500 });
}
if (preferences.getBoolean("notificationStyleLight", false)) {
builder.setLights(0xFF00FF8F, 300, 1000);
}
((NotificationManager) (getSystemService(NOTIFICATION_SERVICE))).notify(NOTIFY_ID, builder.build()); ((NotificationManager) (getSystemService(NOTIFICATION_SERVICE))).notify(NOTIFY_ID, builder.build());
} }
@ -198,6 +188,8 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
.transform(new RoundedTransformation(7, 0)) .transform(new RoundedTransformation(7, 0))
.into(mTarget); .into(mTarget);
} else { } else {
setupPreferences(preferences, builder);
try { try {
builder.setContentTitle(String.format(getString(R.string.notification_title_summary), currentNotifications.length())) builder.setContentTitle(String.format(getString(R.string.notification_title_summary), currentNotifications.length()))
.setContentText(truncateWithEllipses(joinNames(currentNotifications), 40)); .setContentText(truncateWithEllipses(joinNames(currentNotifications), 40));
@ -214,6 +206,20 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
((NotificationManager) (getSystemService(NOTIFICATION_SERVICE))).notify(NOTIFY_ID, builder.build()); ((NotificationManager) (getSystemService(NOTIFICATION_SERVICE))).notify(NOTIFY_ID, builder.build());
} }
private void setupPreferences(SharedPreferences preferences, NotificationCompat.Builder builder) {
if (preferences.getBoolean("notificationAlertSound", true)) {
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
}
if (preferences.getBoolean("notificationStyleVibrate", false)) {
builder.setVibrate(new long[] { 500, 500 });
}
if (preferences.getBoolean("notificationStyleLight", false)) {
builder.setLights(0xFF00FF8F, 300, 1000);
}
}
private String joinNames(JSONArray array) throws JSONException { private String joinNames(JSONArray array) throws JSONException {
if (array.length() > 3) { if (array.length() > 3) {
return String.format(getString(R.string.notification_summary_large), array.get(0), array.get(1), array.get(2), array.length() - 3); return String.format(getString(R.string.notification_summary_large), array.get(0), array.get(1), array.get(2), array.length() - 3);

@ -20,8 +20,9 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Spanned; import android.text.Spanned;
@ -47,7 +48,6 @@ import retrofit2.Callback;
public class SFragment extends Fragment { public class SFragment extends Fragment {
protected String loggedInAccountId; protected String loggedInAccountId;
protected String loggedInUsername; protected String loggedInUsername;
private MastodonAPI api;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -57,7 +57,10 @@ public class SFragment extends Fragment {
getString(R.string.preferences_file_key), Context.MODE_PRIVATE); getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
loggedInAccountId = preferences.getString("loggedInAccountId", null); loggedInAccountId = preferences.getString("loggedInAccountId", null);
loggedInUsername = preferences.getString("loggedInAccountUsername", null); loggedInUsername = preferences.getString("loggedInAccountUsername", null);
api = ((BaseActivity) getActivity()).mastodonAPI; }
public MastodonAPI getApi() {
return ((BaseActivity) getActivity()).mastodonAPI;
} }
protected void reply(Status status) { protected void reply(Status status) {
@ -85,6 +88,11 @@ public class SFragment extends Fragment {
public void onResponse(Call<Status> call, retrofit2.Response<Status> response) { public void onResponse(Call<Status> call, retrofit2.Response<Status> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
status.reblogged = reblog; status.reblogged = reblog;
if (status.reblog != null) {
status.reblog.reblogged = reblog;
}
adapter.notifyItemChanged(position); adapter.notifyItemChanged(position);
} }
} }
@ -96,9 +104,9 @@ public class SFragment extends Fragment {
}; };
if (reblog) { if (reblog) {
api.reblogStatus(id).enqueue(cb); getApi().reblogStatus(id).enqueue(cb);
} else { } else {
api.unreblogStatus(id).enqueue(cb); getApi().unreblogStatus(id).enqueue(cb);
} }
} }
@ -111,6 +119,11 @@ public class SFragment extends Fragment {
public void onResponse(Call<Status> call, retrofit2.Response<Status> response) { public void onResponse(Call<Status> call, retrofit2.Response<Status> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
status.favourited = favourite; status.favourited = favourite;
if (status.reblog != null) {
status.reblog.favourited = favourite;
}
adapter.notifyItemChanged(position); adapter.notifyItemChanged(position);
} }
} }
@ -122,14 +135,14 @@ public class SFragment extends Fragment {
}; };
if (favourite) { if (favourite) {
api.favouriteStatus(id).enqueue(cb); getApi().favouriteStatus(id).enqueue(cb);
} else { } else {
api.unfavouriteStatus(id).enqueue(cb); getApi().unfavouriteStatus(id).enqueue(cb);
} }
} }
private void block(String id) { private void block(String id) {
api.blockAccount(id).enqueue(new Callback<Relationship>() { getApi().blockAccount(id).enqueue(new Callback<Relationship>() {
@Override @Override
public void onResponse(Call<Relationship> call, retrofit2.Response<Relationship> response) { public void onResponse(Call<Relationship> call, retrofit2.Response<Relationship> response) {
@ -143,7 +156,7 @@ public class SFragment extends Fragment {
} }
private void delete(String id) { private void delete(String id) {
api.deleteStatus(id).enqueue(new Callback<ResponseBody>() { getApi().deleteStatus(id).enqueue(new Callback<ResponseBody>() {
@Override @Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
@ -206,13 +219,9 @@ public class SFragment extends Fragment {
protected void viewMedia(String url, Status.MediaAttachment.Type type) { protected void viewMedia(String url, Status.MediaAttachment.Type type) {
switch (type) { switch (type) {
case IMAGE: { case IMAGE: {
Fragment newFragment = ViewMediaFragment.newInstance(url); DialogFragment newFragment = ViewMediaFragment.newInstance(url);
FragmentTransaction ft = getFragmentManager().beginTransaction();
FragmentManager manager = getFragmentManager(); newFragment.show(ft, "view_media");
manager.beginTransaction()
.add(R.id.overlay_fragment_container, newFragment)
.addToBackStack(null)
.commit();
break; break;
} }
case GIFV: case GIFV:

@ -16,21 +16,27 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager;
import com.squareup.picasso.Callback; import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import butterknife.BindView;
import butterknife.ButterKnife;
import uk.co.senab.photoview.PhotoView; import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher; import uk.co.senab.photoview.PhotoViewAttacher;
public class ViewMediaFragment extends Fragment { public class ViewMediaFragment extends DialogFragment {
private PhotoViewAttacher attacher; private PhotoViewAttacher attacher;
@BindView(R.id.view_media_image) PhotoView photoView;
public static ViewMediaFragment newInstance(String url) { public static ViewMediaFragment newInstance(String url) {
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
ViewMediaFragment fragment = new ViewMediaFragment(); ViewMediaFragment fragment = new ViewMediaFragment();
@ -39,14 +45,29 @@ public class ViewMediaFragment extends Fragment {
return fragment; return fragment;
} }
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog_FullScreen);
}
@Override
public void onResume() {
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
super.onResume();
}
@Override @Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_view_media, container, false); View rootView = inflater.inflate(R.layout.fragment_view_media, container, false);
ButterKnife.bind(this, rootView);
Bundle arguments = getArguments(); Bundle arguments = getArguments();
String url = arguments.getString("url"); String url = arguments.getString("url");
PhotoView photoView = (PhotoView) rootView.findViewById(R.id.view_media_image);
attacher = new PhotoViewAttacher(photoView); attacher = new PhotoViewAttacher(photoView);
@ -84,8 +105,4 @@ public class ViewMediaFragment extends Fragment {
attacher.cleanup(); attacher.cleanup();
super.onDestroyView(); super.onDestroyView();
} }
private void dismiss() {
getFragmentManager().popBackStack();
}
} }

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true" android:clickable="true"
android:background="#60000000"> android:layout_gravity="center"
android:background="@android:color/black">
<uk.co.senab.photoview.PhotoView <uk.co.senab.photoview.PhotoView
android:id="@+id/view_media_image" android:id="@+id/view_media_image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
</RelativeLayout> </FrameLayout>

@ -92,6 +92,11 @@
<item name="windowActionBarOverlay">true</item> <item name="windowActionBarOverlay">true</item>
</style> </style>
<style name="Dialog.FullScreen" parent="Theme.AppCompat.Dialog">
<item name="android:padding">0dp</item>
<item name="android:windowBackground">@android:color/black</item>
</style>
<!--Light Application Theme Styles--> <!--Light Application Theme Styles-->
<style name="AppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar"> <style name="AppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar">

Loading…
Cancel
Save