delete stories
This commit is contained in:
parent
971fc07bfb
commit
35ef88b38f
|
@ -543,7 +543,7 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
|
|||
int maxUploadRetryTimes = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3);
|
||||
String url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/pixelfed/v1/media";
|
||||
if (pixelfedStory) {
|
||||
url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/pixelfed/stories/v1/add";
|
||||
url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/stories/v0/add";
|
||||
}
|
||||
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
|
||||
uploadConfig
|
||||
|
@ -558,9 +558,7 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
|
|||
request.addHeader("x-csrf-token", tokens[1].replace("X-CSRF-TOKEN= ", ""));
|
||||
request.setNotificationConfig(uploadConfig);
|
||||
request.addFileToUpload(uri.toString().replace("file://", ""), "file");
|
||||
if (!pixelfedStory) {
|
||||
request.addParameter("filename", fileName).setMaxRetries(maxUploadRetryTimes);
|
||||
}
|
||||
request.addParameter("filename", fileName).setMaxRetries(maxUploadRetryTimes);
|
||||
request.startUpload();
|
||||
} catch (MalformedURLException | FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -3,6 +3,7 @@ package app.fedilab.android.client;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
@ -224,6 +225,25 @@ public class PixelfedAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a media in story
|
||||
*
|
||||
* @param id String id of the object
|
||||
*/
|
||||
public void deleteStory(String id) {
|
||||
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.postJson(getAbsoluteUrl("/delete/" + id), 30, new JsonObject(), prefKeyOauthTokenT);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts a story
|
||||
*
|
||||
|
@ -282,27 +302,6 @@ public class PixelfedAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Pixelfed Story *synchronously*
|
||||
*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public int deleteStory(String id) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
HttpsConnection httpsConnection;
|
||||
try {
|
||||
httpsConnection = new HttpsConnection(context, this.instance);
|
||||
httpsConnection.delete(getAbsoluteUrl("/delete"), 10, params, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return actionCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the error message
|
||||
|
|
|
@ -63,10 +63,12 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
private Context context;
|
||||
private final List<PixelFedStory> stories;
|
||||
private ArrayList<Attachment> attachments;
|
||||
private final String userId;
|
||||
|
||||
public PixelfedStoriesListAdapter(List<PixelFedStory> stories) {
|
||||
public PixelfedStoriesListAdapter(List<PixelFedStory> stories, String userId) {
|
||||
super();
|
||||
this.stories = stories;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
|
||||
|
@ -157,30 +159,13 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
|
||||
|
||||
holder.art_media_play.setVisibility(View.GONE);
|
||||
if (attachments != null && attachments.size() > 1) {
|
||||
SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), false, attachments);
|
||||
if (attachments != null && attachments.size() > 0) {
|
||||
SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), true, attachments, userId);
|
||||
holder.imageSlider.setSliderAdapter(sliderAdapter);
|
||||
holder.imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM);
|
||||
holder.imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
|
||||
holder.art_media.setVisibility(View.GONE);
|
||||
holder.imageSlider.setVisibility(View.VISIBLE);
|
||||
} else if (attachments != null && attachments.size() > 0) {
|
||||
holder.art_media.setVisibility(View.VISIBLE);
|
||||
holder.imageSlider.setVisibility(View.GONE);
|
||||
if (attachments.get(0).getType().toLowerCase().equals("video")) {
|
||||
holder.art_media_play.setVisibility(View.VISIBLE);
|
||||
}
|
||||
String url;
|
||||
if (attachments.get(0).getPreview_url().endsWith("no-preview.png")) {
|
||||
url = attachments.get(0).getUrl();
|
||||
} else {
|
||||
url = attachments.get(0).getPreview_url();
|
||||
}
|
||||
Glide.with(holder.itemView.getContext())
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.into(holder.art_media);
|
||||
}
|
||||
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
|
|
|
@ -18,12 +18,16 @@ package app.fedilab.android.drawers;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -57,8 +61,10 @@ import app.fedilab.android.asynctasks.UpdateDescriptionAttachmentAsyncTask;
|
|||
import app.fedilab.android.client.Entities.Attachment;
|
||||
import app.fedilab.android.client.Entities.Error;
|
||||
import app.fedilab.android.client.Entities.Status;
|
||||
import app.fedilab.android.client.PixelfedAPI;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.interfaces.OnRetrieveAttachmentInterface;
|
||||
import app.fedilab.android.sqlite.Sqlite;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
@ -71,7 +77,17 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
|
|||
private final WeakReference<Activity> contextWeakReference;
|
||||
private final boolean canDelete;
|
||||
private final SliderAdapter sliderAdapter;
|
||||
private boolean isStory = false;
|
||||
private String userId;
|
||||
|
||||
public SliderAdapter(WeakReference<Activity> contextWeakReference, boolean delete, ArrayList<Attachment> attachments, String userId) {
|
||||
this.attachments = attachments;
|
||||
this.contextWeakReference = contextWeakReference;
|
||||
this.canDelete = delete;
|
||||
this.sliderAdapter = this;
|
||||
this.isStory = true;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public SliderAdapter(WeakReference<Activity> contextWeakReference, boolean delete, ArrayList<Attachment> attachments) {
|
||||
this.attachments = attachments;
|
||||
|
@ -169,8 +185,9 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
|
|||
}
|
||||
});
|
||||
} else {
|
||||
viewHolder.imageViewBackground.setOnClickListener(v -> showAddDescription(attachments.get(position)));
|
||||
|
||||
if (!isStory) {
|
||||
viewHolder.imageViewBackground.setOnClickListener(v -> showAddDescription(attachments.get(position)));
|
||||
}
|
||||
viewHolder.delete_media.setOnClickListener(view -> showRemove(position));
|
||||
}
|
||||
|
||||
|
@ -255,10 +272,28 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
|
|||
dialog.setMessage(R.string.toot_delete_media);
|
||||
dialog.setNegativeButton(R.string.cancel, (dialog1, which) -> dialog1.dismiss());
|
||||
dialog.setPositiveButton(R.string.yes, (dialog12, which) -> {
|
||||
attachments.remove(attachments.get(position));
|
||||
sliderAdapter.notifyDataSetChanged();
|
||||
if (contextWeakReference.get() instanceof PixelfedComposeActivity) {
|
||||
((PixelfedComposeActivity) contextWeakReference.get()).redraw();
|
||||
String userIdOwner = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if (attachments.size() > position) {
|
||||
if (isStory && userId.compareTo(userIdOwner) == 0) {
|
||||
new Thread(() -> {
|
||||
new PixelfedAPI(contextWeakReference.get()).deleteStory(attachments.get(position).getId());
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
attachments.remove(attachments.get(position));
|
||||
sliderAdapter.notifyDataSetChanged();
|
||||
if (contextWeakReference.get() instanceof PixelfedComposeActivity) {
|
||||
((PixelfedComposeActivity) contextWeakReference.get()).redraw();
|
||||
}
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
}
|
||||
} else {
|
||||
attachments.remove(attachments.get(position));
|
||||
sliderAdapter.notifyDataSetChanged();
|
||||
if (contextWeakReference.get() instanceof PixelfedComposeActivity) {
|
||||
((PixelfedComposeActivity) contextWeakReference.get()).redraw();
|
||||
}
|
||||
}
|
||||
dialog12.dismiss();
|
||||
});
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DisplayStoriesFragment extends Fragment implements OnRetrieveStorie
|
|||
textviewNoAction = rootView.findViewById(R.id.no_action);
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
pixelfedStoriesListAdapter = new PixelfedStoriesListAdapter(this.pixelFedStories);
|
||||
pixelfedStoriesListAdapter = new PixelfedStoriesListAdapter(this.pixelFedStories, userId);
|
||||
lv_stories.setAdapter(pixelfedStoriesListAdapter);
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_stories.setLayoutManager(mLayoutManager);
|
||||
|
|
Loading…
Reference in New Issue