Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 139 additions & 0 deletions app/src/main/java/ir/textmining/app/model/TagsLegend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package ir.textmining.app.model;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;

import com.google.android.material.card.MaterialCardView;
import com.google.gson.annotations.SerializedName;
import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.items.AbstractItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import ir.textmining.app.R;

public class TagsLegend extends AbstractItem<TagsLegend, TagsLegend.MyViewHolder> {

private Long id;

@SerializedName("PersianName")
private String persianName;

@SerializedName("Description")
private String description;

@SerializedName("Shortcut")
private String shortcut;

@SerializedName("Color")
private String color;

@SerializedName("Title")
private String title;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getPersianName() {
return persianName;
}

public void setPersianName(String persianName) {
this.persianName = persianName;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getShortcut() {
return shortcut;
}

public void setShortcut(String shortcut) {
this.shortcut = shortcut;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

@NonNull
@Override
public MyViewHolder getViewHolder(@NonNull View view) {
return new MyViewHolder(view);
}

@Override
public int getType() {
return R.id.fastadapter_item_adapter;
}

@Override
public int getLayoutRes() {
return R.layout.item_tag_legend;
}


protected static class MyViewHolder extends FastAdapter.ViewHolder<TagsLegend> {
View view;
@BindView(R.id.title_text_view)
AppCompatTextView titleTextView;
@BindView(R.id.description_text_view)
AppCompatTextView descriptionTextView;
@BindView(R.id.card_view)
MaterialCardView cardView;

MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
this.view = view;
}

@Override
public void bindView(@NonNull TagsLegend item, @NonNull List<Object> payloads) {
titleTextView.setText(String.format("%s", item.getPersianName()));
cardView.setCardBackgroundColor(Color.parseColor(item.getColor()));
descriptionTextView.setText(item.getDescription());
if (item.getTitle().equals("O")) {
titleTextView.setTextColor(Color.BLACK);
descriptionTextView.setTextColor(Color.BLACK);
} else {
titleTextView.setTextColor(Color.WHITE);
descriptionTextView.setTextColor(Color.WHITE);
}
}

@Override
public void unbindView(@NonNull TagsLegend item) {
titleTextView.setText(null);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import ir.textmining.app.ui.fragment.AboutFragment;
import ir.textmining.app.ui.fragment.SelectTagFragment;
import ir.textmining.app.ui.fragment.SettingsFragment;
import ir.textmining.app.ui.fragment.TagLegendFragment;
import ir.textmining.app.util.AppUtil;
import ir.textmining.app.util.Constant;
import ir.textmining.app.util.MyApplication;
Expand Down Expand Up @@ -236,6 +237,11 @@ public void nextSentence() {
getSentence();
}

@OnClick(R.id.legend_button)
public void showLegend() {
AppUtil.showFragment(new TagLegendFragment(), getSupportFragmentManager());
}

private void showSkeleton() {
skeletonScreen = Skeleton.bind(chipGroup)
.shimmer(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package ir.textmining.app.ui.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.adapters.ItemAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.objectbox.Box;
import io.objectbox.BoxStore;
import ir.textmining.app.R;
import ir.textmining.app.model.NerStandardTagsItem;
import ir.textmining.app.model.TagsLegend;
import ir.textmining.app.util.AppUtil;
import ir.textmining.app.util.MyApplication;

public class TagLegendFragment extends DialogFragment {
@BindView(R.id.title)
AppCompatTextView title;
@BindView(R.id.recyclerView)
RecyclerView recyclerView;
private Box<NerStandardTagsItem> tagsItemBox;
private FastAdapter<TagsLegend> mFastAdapter;
private ItemAdapter<TagsLegend> mItemAdapter;


@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tag_legend,
container, false);
ButterKnife.bind(this, view);
initVariables();
setUpRecyclerView();
handleTagItems();
return view;
}

private void initVariables() {
BoxStore boxStore = MyApplication.getBoxStore();
tagsItemBox = boxStore.boxFor(NerStandardTagsItem.class);
}

private void setUpRecyclerView() {
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 1);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
mItemAdapter = new ItemAdapter<>();
mFastAdapter = FastAdapter.with(mItemAdapter);
recyclerView.setAdapter(mFastAdapter);
}

private void handleTagItems() {
List<NerStandardTagsItem> tagsItems = tagsItemBox.getAll();
mItemAdapter.clear();
mItemAdapter.add(AppUtil.convertToTagsLegend(tagsItems));
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.getWindow().setAttributes(lp);
return dialog;
}

@OnClick(R.id.close_button)
void close() {
dismiss();
if (getFragmentManager() != null) {
getFragmentManager().popBackStack();
}
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/ir/textmining/app/util/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@

import com.blankj.utilcode.util.SnackbarUtils;

import java.util.ArrayList;
import java.util.List;

import io.objectbox.Box;
import ir.textmining.app.R;
import ir.textmining.app.model.AuthInfo;
import ir.textmining.app.model.NerStandardTagsItem;
import ir.textmining.app.model.NerStandardTagsItem_;
import ir.textmining.app.model.TagsLegend;

public class AppUtil {

Expand Down Expand Up @@ -83,4 +87,19 @@ public void onClick(View v) {
}
}, 100);
}

public static List<TagsLegend> convertToTagsLegend(List<NerStandardTagsItem> tagsItems) {
List<TagsLegend> tagsLegends = new ArrayList<>();
for (NerStandardTagsItem item : tagsItems) {
TagsLegend tagsLegend = new TagsLegend();
tagsLegend.setColor(item.getColor());
tagsLegend.setDescription(item.getDescription());
tagsLegend.setId(item.getId());
tagsLegend.setPersianName(item.getPersianName());
tagsLegend.setShortcut(item.getShortcut());
tagsLegend.setTitle(item.getTitle());
tagsLegends.add(tagsLegend);
}
return tagsLegends;
}
}
32 changes: 24 additions & 8 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
android:orientation="horizontal"
android:padding="@dimen/spacing_large">

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/sentence_label"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:textStyle="bold|italic" />

<com.google.android.material.button.MaterialButton
android:id="@+id/next_sentence_button"
style="@style/Widget.MaterialComponents.Button"
Expand All @@ -36,6 +28,21 @@
app:cornerRadius="6dp"
app:icon="@drawable/ic_navigate_next_black_24dp"
app:iconTint="@android:color/white" />

<View
android:layout_width="@dimen/spacing_large"
android:layout_height="0dp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/legend_button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layoutDirection="locale"
android:text="@string/legend_label"
android:textAllCaps="false"
app:cornerRadius="6dp"
app:icon="@drawable/ic_info_outline_black_24dp" />
</LinearLayout>

<View
Expand All @@ -45,6 +52,15 @@
android:layout_marginEnd="@dimen/spacing_xlarge"
android:background="@color/grey_10" />

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/spacing_large"
android:paddingEnd="@dimen/spacing_large"
android:text="@string/sentence_label"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:textStyle="bold|italic" />

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Loading