Skip to content

Commit

Permalink
news: move functions into adapterNews (fixes #2536) (#2540)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Sep 27, 2023
1 parent 9026ae6 commit f7b7ad3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 89 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1059
versionName "0.10.59"
versionCode 1060
versionName "0.10.60"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down

This file was deleted.

66 changes: 62 additions & 4 deletions app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.google.android.flexbox.FlexboxLayout;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import org.ole.planet.myplanet.R;
import org.ole.planet.myplanet.base.BaseNewsAdapter;
import org.ole.planet.myplanet.model.RealmMyLibrary;
import org.ole.planet.myplanet.model.RealmNews;
import org.ole.planet.myplanet.model.RealmUserModel;
Expand All @@ -30,6 +34,7 @@
import org.ole.planet.myplanet.utilities.Utilities;

import java.io.File;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

Expand All @@ -40,14 +45,16 @@
import io.realm.RealmList;
import io.realm.Sort;

public class AdapterNews extends BaseNewsAdapter {
public class AdapterNews extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<RealmNews> list;

private OnNewsItemClickListener listener;
private RealmNews parentNews;

private ChipCloudConfig config;
private RealmList<String> imageList;
public Realm mRealm;
public Context context;
public RealmUserModel currentUser;
public boolean fromLogin;

public void setImageList(RealmList<String> imageList) {
this.imageList = imageList;
Expand Down Expand Up @@ -292,4 +299,55 @@ public interface OnNewsItemClickListener {

void addImage(LinearLayout llImage);
}

public String getLabel(String s) {
for (String key : Constants.LABELS.keySet()) {
if (s.equals(Constants.LABELS.get(key))) {
return key;
}
}
return "";
}

public void showShareButton(RecyclerView.ViewHolder holder, RealmNews news) {
((ViewHolderNews) holder).btnShare.setVisibility((news.isCommunityNews() || fromLogin) ? View.GONE : View.VISIBLE);
((ViewHolderNews) holder).btnShare.setOnClickListener(view -> {
JsonArray array = new Gson().fromJson(news.getViewIn(), JsonArray.class);
JsonObject ob = new JsonObject();
ob.addProperty("section", "community");
ob.addProperty("_id", currentUser.getPlanetCode() + "@" + currentUser.getParentCode());
ob.addProperty("sharedDate", Calendar.getInstance().getTimeInMillis());
array.add(ob);
if (!mRealm.isInTransaction()) mRealm.beginTransaction();
news.setViewIn(new Gson().toJson(array));
mRealm.commitTransaction();
Utilities.toast(context, context.getString(R.string.shared_to_community));
((ViewHolderNews) holder).btnShare.setVisibility(View.GONE);
});
}

public class ViewHolderNews extends RecyclerView.ViewHolder {
public TextView tvName, tvDate, tvMessage;
public ImageView imgEdit, imgDelete, imgUser, newsImage;
public LinearLayout llEditDelete;
public FlexboxLayout fbChips;
public Button btnReply, btnShowReply, btnAddLabel, btnShare;

public ViewHolderNews(View itemView) {
super(itemView);
tvDate = itemView.findViewById(R.id.tv_date);
tvName = itemView.findViewById(R.id.tv_name);
tvMessage = itemView.findViewById(R.id.tv_message);
imgDelete = itemView.findViewById(R.id.img_delete);
imgEdit = itemView.findViewById(R.id.img_edit);
imgUser = itemView.findViewById(R.id.img_user);
llEditDelete = itemView.findViewById(R.id.ll_edit_delete);
btnReply = itemView.findViewById(R.id.btn_reply);
btnShowReply = itemView.findViewById(R.id.btn_show_reply);
btnAddLabel = itemView.findViewById(R.id.btn_add_label);
btnShare = itemView.findViewById(R.id.btn_share);
newsImage = itemView.findViewById(R.id.img_news);
fbChips = itemView.findViewById(R.id.fb_chips);
}
}
}

0 comments on commit f7b7ad3

Please sign in to comment.