Skip to content

Commit

Permalink
directmessage bug fix, layout fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Jan 16, 2022
1 parent 1c25c70 commit 9b8c298
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,8 @@ else if (v.getId() == R.id.tweet_location_coordinate) {
// open tweet media
else if (v.getId() == R.id.tweet_media_attach) {
// convert links to uri
Uri[] links = clickedTweet.getMediaLinks();
Intent mediaIntent = new Intent(this, MediaViewer.class);
mediaIntent.putExtra(KEY_MEDIA_URI, links);
mediaIntent.putExtra(KEY_MEDIA_URI, clickedTweet.getMediaLinks());
switch (clickedTweet.getMediaType()) {
case Tweet.MIME_PHOTO:
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE);
Expand Down
22 changes: 8 additions & 14 deletions app/src/main/java/org/nuclearfog/twidda/adapter/ImageAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
import androidx.recyclerview.widget.RecyclerView.Adapter;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import com.squareup.picasso.Picasso;

import org.nuclearfog.twidda.adapter.holder.Footer;
import org.nuclearfog.twidda.adapter.holder.ImageItem;
import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
import org.nuclearfog.twidda.adapter.holder.ImageHolder;
import org.nuclearfog.twidda.database.GlobalSettings;

import java.util.ArrayList;
Expand All @@ -42,22 +39,19 @@ public class ImageAdapter extends Adapter<ViewHolder> {
private static final int LOADING = 1;

private OnImageClickListener itemClickListener;

private GlobalSettings settings;

private Picasso picasso;

private List<Uri> imageUri = new ArrayList<>(5);
private boolean loading = false;
private boolean saveImg = true;
private boolean enableSaveButton = true;

/**
* @param itemClickListener click listener
*/
public ImageAdapter(Context context, OnImageClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
this.settings = GlobalSettings.getInstance(context);
picasso = PicassoBuilder.get(context);
}

/**
Expand Down Expand Up @@ -88,7 +82,7 @@ public void disableLoading() {
* disable save button on images
*/
public void disableSaveButton() {
saveImg = false;
enableSaveButton = false;
}

/**
Expand Down Expand Up @@ -121,7 +115,7 @@ public int getItemCount() {
@Override
public ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
if (viewType == PICTURE) {
final ImageItem item = new ImageItem(parent, settings);
final ImageHolder item = new ImageHolder(parent, settings);
item.preview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -131,7 +125,7 @@ public void onClick(View v) {
}
}
});
if (saveImg) {
if (enableSaveButton) {
item.saveButton.setVisibility(VISIBLE);
item.saveButton.setOnClickListener(new OnClickListener() {
@Override
Expand All @@ -152,10 +146,10 @@ public void onClick(View v) {

@Override
public void onBindViewHolder(@NonNull ViewHolder vh, int index) {
if (vh instanceof ImageItem) {
ImageItem item = (ImageItem) vh;
if (vh instanceof ImageHolder) {
ImageHolder item = (ImageHolder) vh;
Uri uri = imageUri.get(index);
picasso.load(uri).into(item.preview);
item.preview.setImageURI(uri);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
* @author nuclearfog
* @see org.nuclearfog.twidda.adapter.ImageAdapter
*/
public class ImageItem extends ViewHolder {
public class ImageHolder extends ViewHolder {

public final ImageView preview;
public final ImageButton saveButton;

/**
* @param parent Parent view from adapter
*/
public ImageItem(ViewGroup parent, GlobalSettings settings) {
public ImageHolder(ViewGroup parent, GlobalSettings settings) {
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image, parent, false));
// get views
CardView cardBackground = (CardView) itemView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;

Expand Down Expand Up @@ -78,7 +79,7 @@ protected Boolean doInBackground(Uri[] links) {
return true;
} catch (TwitterException err) {
this.err = err;
} catch (Exception exception) {
} catch (IOException exception) {
exception.printStackTrace();
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.nuclearfog.twidda.activities.MediaActivity;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -45,7 +46,7 @@ protected Boolean doInBackground(Object... data) {
return true;
}
}
} catch (Exception err) {
} catch (IOException err) {
err.printStackTrace();
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void onClick(DirectMessage message, Action action) {
case MEDIA:
if (message.getMedia() != null) {
Intent mediaIntent = new Intent(requireContext(), MediaViewer.class);
mediaIntent.putExtra(KEY_MEDIA_URI, message.getMedia());
mediaIntent.putExtra(KEY_MEDIA_URI, new Uri[]{message.getMedia()});
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE);
startActivity(mediaIntent);
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_dm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
android:layout_height="@dimen/dmitem_button_media_height"
android:visibility="gone"
android:contentDescription="@string/directmessage_media_button"
android:layout_margin="@dimen/dmitem_button_media_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/dm_button_barrier"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/layout/item_image.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_margin="@dimen/imageitem_layout_margin"
style="@style/CardViewStyle">

<ImageView
android:id="@+id/item_image_preview"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/image_preview"
android:scaleType="fitCenter" />
android:scaleType="fitStart"
android:adjustViewBounds="true"/>

<ImageButton
android:id="@+id/item_image_save"
android:layout_width="@dimen/imageitem_button_size"
android:layout_height="@dimen/imageitem_button_size"
android:visibility="invisible"
android:visibility="gone"
android:padding="@dimen/imageitem_drawable_padding"
android:layout_margin="@dimen/imageitem_button_margin"
android:layout_gravity="top|end"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/page_media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
android:visibility="invisible"
android:layout_margin="@dimen/mediapage_preview_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<dimen name="dmitem_icon_size">16sp</dimen>
<dimen name="dmitem_button_media_width">48dp</dimen>
<dimen name="dmitem_button_media_height">30dp</dimen>
<dimen name="dmitem_button_media_margin">10dp</dimen>

<!--dimens of page_login.xml-->
<dimen name="loginpage_toolbar_height">@dimen/toolbar_height</dimen>
Expand Down

0 comments on commit 9b8c298

Please sign in to comment.