mirror of
https://github.com/SoPat712/TrackCovid19.git
synced 2025-08-27 21:02:18 -04:00
Initial Upload
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.AbstractTableAdapter;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.CellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.MoneyCellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.RowHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class CountriesTableAdapter extends AbstractTableAdapter<ColumnHeaderModel, RowHeaderModel,
|
||||
CellModel> {
|
||||
|
||||
private CountriesTableViewModel myTableViewModel;
|
||||
|
||||
public CountriesTableAdapter(Context p_jContext) {
|
||||
super(p_jContext);
|
||||
|
||||
this.myTableViewModel = new CountriesTableViewModel();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateCellViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout;
|
||||
|
||||
switch (viewType) {
|
||||
|
||||
default:
|
||||
// Get default Cell xml Layout
|
||||
layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_cell_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Cell ViewHolder
|
||||
return new CellViewHolder(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindCellViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition, int p_nYPosition) {
|
||||
CellModel cell = (CellModel) p_jValue;
|
||||
|
||||
if (holder instanceof CellViewHolder) {
|
||||
// Get the holder to update cell item text
|
||||
((CellViewHolder) holder).setCellModel(cell, p_nXPosition);
|
||||
|
||||
} else if (holder instanceof MoneyCellViewHolder) {
|
||||
((MoneyCellViewHolder) holder).setCellModel(cell);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSorterViewHolder onCreateColumnHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout
|
||||
.tableview_column_header_layout, parent, false);
|
||||
|
||||
return new ColumnHeaderViewHolder(layout, getTableView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindColumnHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition) {
|
||||
ColumnHeaderModel columnHeader = (ColumnHeaderModel) p_jValue;
|
||||
|
||||
// Get the holder to update cell item text
|
||||
ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder;
|
||||
|
||||
columnHeaderViewHolder.setColumnHeaderModel(columnHeader, p_nXPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateRowHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
// Get Row Header xml Layout
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_row_header_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Row Header ViewHolder
|
||||
return new RowHeaderViewHolder(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindRowHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nYPosition) {
|
||||
|
||||
RowHeaderModel rowHeaderModel = (RowHeaderModel) p_jValue;
|
||||
|
||||
RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder;
|
||||
rowHeaderViewHolder.row_header_textview.setText(rowHeaderModel.getData());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateCornerView() {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.tableview_corner_layout, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellItemViewType(int position) {
|
||||
return myTableViewModel.getCellItemViewType(position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is not a generic Adapter method. It helps to generate lists from single user
|
||||
* list for this adapter.
|
||||
*/
|
||||
public void setCountriesList(List<Countries> countriesList) {
|
||||
// Generate the lists that are used to TableViewAdapter
|
||||
myTableViewModel.generateListForTableView(countriesList);
|
||||
|
||||
// Now we got what we need to show on TableView.
|
||||
setAllItems(myTableViewModel.getColumHeaderModeList(), myTableViewModel
|
||||
.getRowHeaderModelList(), myTableViewModel.getCellModelList());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,203 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 4.02.2018.
|
||||
*/
|
||||
|
||||
public class CountriesTableViewModel {
|
||||
|
||||
|
||||
private List<ColumnHeaderModel> mColumnHeaderModelList;
|
||||
private List<RowHeaderModel> mRowHeaderModelList;
|
||||
private List<List<CellModel>> mCellModelList;
|
||||
|
||||
public int getCellItemViewType(int column) {
|
||||
|
||||
switch (column) {
|
||||
/*
|
||||
case 5:
|
||||
// 5. column header is gender.
|
||||
return GENDER_TYPE;
|
||||
case 8:
|
||||
// 8. column header is Salary.
|
||||
return MONEY_TYPE;
|
||||
|
||||
*/
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- Each of Column Header -
|
||||
"Id"
|
||||
"Name"
|
||||
"Nickname"
|
||||
"Email"
|
||||
"Birthday"
|
||||
"Gender"
|
||||
"Age"
|
||||
"Job"
|
||||
"Salary"
|
||||
"CreatedAt"
|
||||
"UpdatedAt"
|
||||
"Address"
|
||||
"Zip Code"
|
||||
"Phone"
|
||||
"Fax"
|
||||
*/
|
||||
|
||||
public int getColumnTextAlign(int column) {
|
||||
switch (column) {
|
||||
// Id
|
||||
case 0:
|
||||
return Gravity.CENTER;
|
||||
// Name
|
||||
case 1:
|
||||
return Gravity.LEFT;
|
||||
// Nickname
|
||||
case 2:
|
||||
return Gravity.LEFT;
|
||||
// Email
|
||||
case 3:
|
||||
return Gravity.LEFT;
|
||||
// BirthDay
|
||||
case 4:
|
||||
return Gravity.CENTER;
|
||||
// Gender (Sex)
|
||||
case 5:
|
||||
return Gravity.CENTER;
|
||||
// Age
|
||||
case 6:
|
||||
return Gravity.CENTER;
|
||||
// Job
|
||||
case 7:
|
||||
return Gravity.LEFT;
|
||||
// Salary
|
||||
case 8:
|
||||
return Gravity.CENTER;
|
||||
// CreatedAt
|
||||
case 9:
|
||||
return Gravity.CENTER;
|
||||
// UpdatedAt
|
||||
case 10:
|
||||
return Gravity.CENTER;
|
||||
// Address
|
||||
case 11:
|
||||
return Gravity.LEFT;
|
||||
// Zip Code
|
||||
case 12:
|
||||
return Gravity.RIGHT;
|
||||
// Phone
|
||||
case 13:
|
||||
return Gravity.RIGHT;
|
||||
// Fax
|
||||
case 14:
|
||||
return Gravity.RIGHT;
|
||||
default:
|
||||
return Gravity.CENTER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<ColumnHeaderModel> createColumnHeaderModelList() {
|
||||
List<ColumnHeaderModel> list = new ArrayList<>();
|
||||
|
||||
// Create Column Headers
|
||||
list.add(new ColumnHeaderModel("Country"));
|
||||
// list.add(new ColumnHeaderModel("Flag"));
|
||||
list.add(new ColumnHeaderModel("Cases"));
|
||||
list.add(new ColumnHeaderModel("Today's Cases"));
|
||||
list.add(new ColumnHeaderModel("Deaths"));
|
||||
list.add(new ColumnHeaderModel("Today's Deaths"));
|
||||
list.add(new ColumnHeaderModel("Active"));
|
||||
|
||||
/*
|
||||
list.add(new ColumnHeaderModel("Cases"));
|
||||
list.add(new ColumnHeaderModel("Today's Cases"));
|
||||
list.add(new ColumnHeaderModel("Deaths"));
|
||||
list.add(new ColumnHeaderModel("Today's Deaths"));
|
||||
list.add(new ColumnHeaderModel("Active Cases"));
|
||||
*/
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<List<CellModel>> createCellModelList(List<Countries> countriesList) {
|
||||
List<List<CellModel>> lists = new ArrayList<>();
|
||||
|
||||
// Creating cell model list from User list for Cell Items
|
||||
// In this example, State list is populated from web service
|
||||
|
||||
for (int i = 0; i < countriesList.size(); i++) {
|
||||
Countries country_data = countriesList.get(i);
|
||||
|
||||
List<CellModel> list = new ArrayList<>();
|
||||
|
||||
// The order should be same with column header list;
|
||||
list.add(new CellModel("1-" + i, country_data.country)); // "Id"
|
||||
// list.add(new CellModel("1-" + i, Html.ImageGetter(country_data.flag);
|
||||
list.add(new CellModel("2-" + i, country_data.cases));
|
||||
list.add(new CellModel("3-" + i, country_data.todayCases));
|
||||
list.add(new CellModel("4-" + i, country_data.deaths));
|
||||
list.add(new CellModel("5-" + i, country_data.todayDeaths));
|
||||
list.add(new CellModel("6-" + i, country_data.active));
|
||||
|
||||
|
||||
/*
|
||||
list.add(new CellModel("2-" + i, country_data.cases)); // "Name"
|
||||
list.add(new CellModel("3-" + i, country_data.todayCases)); // "Nickname"
|
||||
list.add(new CellModel("4-" + i, country_data.deaths)); // "Email"
|
||||
list.add(new CellModel("5-" + i, country_data.todayDeaths)); // "BirthDay"
|
||||
list.add(new CellModel("6-" + i, country_data.active));
|
||||
*/
|
||||
// Add
|
||||
lists.add(list);
|
||||
}
|
||||
|
||||
return lists;
|
||||
}
|
||||
|
||||
private List<RowHeaderModel> createRowHeaderList(int size) {
|
||||
List<RowHeaderModel> list = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
// In this example, Row headers just shows the index of the TableView List.
|
||||
list.add(new RowHeaderModel(String.valueOf(i + 1)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public List<ColumnHeaderModel> getColumHeaderModeList() {
|
||||
return mColumnHeaderModelList;
|
||||
}
|
||||
|
||||
public List<RowHeaderModel> getRowHeaderModelList() {
|
||||
return mRowHeaderModelList;
|
||||
}
|
||||
|
||||
public List<List<CellModel>> getCellModelList() {
|
||||
return mCellModelList;
|
||||
}
|
||||
|
||||
|
||||
public void generateListForTableView(List<Countries> countries) {
|
||||
mColumnHeaderModelList = createColumnHeaderModelList();
|
||||
mCellModelList = createCellModelList(countries);
|
||||
mRowHeaderModelList = createRowHeaderList(countries.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
145
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableAdapter.java
Executable file
145
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableAdapter.java
Executable file
@@ -0,0 +1,145 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.AbstractTableAdapter;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.CellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.MoneyCellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.RowHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class MyTableAdapter extends AbstractTableAdapter<ColumnHeaderModel, RowHeaderModel,
|
||||
CellModel> {
|
||||
|
||||
private MyTableViewModel myTableViewModel;
|
||||
|
||||
public MyTableAdapter(Context p_jContext) {
|
||||
super(p_jContext);
|
||||
|
||||
this.myTableViewModel = new MyTableViewModel();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateCellViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout;
|
||||
|
||||
switch (viewType) {
|
||||
|
||||
default:
|
||||
// Get default Cell xml Layout
|
||||
layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_cell_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Cell ViewHolder
|
||||
return new CellViewHolder(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindCellViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition, int p_nYPosition) {
|
||||
CellModel cell = (CellModel) p_jValue;
|
||||
|
||||
if (holder instanceof CellViewHolder) {
|
||||
// Get the holder to update cell item text
|
||||
((CellViewHolder) holder).setCellModel(cell, p_nXPosition);
|
||||
|
||||
} else if (holder instanceof MoneyCellViewHolder) {
|
||||
((MoneyCellViewHolder) holder).setCellModel(cell);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSorterViewHolder onCreateColumnHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout
|
||||
.tableview_column_header_layout, parent, false);
|
||||
|
||||
return new ColumnHeaderViewHolder(layout, getTableView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindColumnHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition) {
|
||||
ColumnHeaderModel columnHeader = (ColumnHeaderModel) p_jValue;
|
||||
|
||||
// Get the holder to update cell item text
|
||||
ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder;
|
||||
|
||||
columnHeaderViewHolder.setColumnHeaderModel(columnHeader, p_nXPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateRowHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
// Get Row Header xml Layout
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_row_header_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Row Header ViewHolder
|
||||
return new RowHeaderViewHolder(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindRowHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nYPosition) {
|
||||
|
||||
RowHeaderModel rowHeaderModel = (RowHeaderModel) p_jValue;
|
||||
|
||||
RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder;
|
||||
rowHeaderViewHolder.row_header_textview.setText(rowHeaderModel.getData());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateCornerView() {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.tableview_corner_layout, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellItemViewType(int position) {
|
||||
return myTableViewModel.getCellItemViewType(position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is not a generic Adapter method. It helps to generate lists from single user
|
||||
* list for this adapter.
|
||||
*/
|
||||
public void setStatesList(List<States> statesList) {
|
||||
// Generate the lists that are used to TableViewAdapter
|
||||
myTableViewModel.generateListForTableView(statesList);
|
||||
|
||||
// Now we got what we need to show on TableView.
|
||||
setAllItems(myTableViewModel.getColumHeaderModeList(), myTableViewModel
|
||||
.getRowHeaderModelList(), myTableViewModel.getCellModelList());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.evrencoskun.tableview.ITableView;
|
||||
import com.evrencoskun.tableview.listener.ITableViewListener;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.popup.ColumnHeaderLongPressPopup;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 2.12.2017.
|
||||
*/
|
||||
|
||||
public class MyTableViewListener implements ITableViewListener {
|
||||
private static final String LOG_TAG = MyTableViewListener.class.getSimpleName();
|
||||
|
||||
private ITableView mTableView;
|
||||
|
||||
public MyTableViewListener(ITableView pTableView) {
|
||||
this.mTableView = pTableView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCellClicked(@NonNull RecyclerView.ViewHolder cellView, int column, int row) {
|
||||
Log.d(LOG_TAG, "onCellClicked has been clicked for x= " + column + " y= " + row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCellLongPressed(@NonNull RecyclerView.ViewHolder cellView, int column, int row) {
|
||||
Log.d(LOG_TAG, "onCellLongPressed has been clicked for " + row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColumnHeaderClicked(@NonNull RecyclerView.ViewHolder columnHeaderView, int
|
||||
column) {
|
||||
Log.d(LOG_TAG, "onColumnHeaderClicked has been clicked for " + column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColumnHeaderLongPressed(@NonNull RecyclerView.ViewHolder columnHeaderView, int
|
||||
column) {
|
||||
if (columnHeaderView != null && columnHeaderView instanceof ColumnHeaderViewHolder) {
|
||||
|
||||
// Create Long Press Popup
|
||||
ColumnHeaderLongPressPopup popup = new ColumnHeaderLongPressPopup(
|
||||
(ColumnHeaderViewHolder) columnHeaderView, mTableView);
|
||||
|
||||
// Show
|
||||
popup.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRowHeaderClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) {
|
||||
Log.d(LOG_TAG, "onRowHeaderClicked has been clicked for " + row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRowHeaderLongPressed(@NonNull RecyclerView.ViewHolder owHeaderView, int row) {
|
||||
Log.d(LOG_TAG, "onRowHeaderLongPressed has been clicked for " + row);
|
||||
}
|
||||
}
|
188
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewModel.java
Executable file
188
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewModel.java
Executable file
@@ -0,0 +1,188 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 4.02.2018.
|
||||
*/
|
||||
|
||||
public class MyTableViewModel {
|
||||
// View Types
|
||||
public static final int GENDER_TYPE = 1;
|
||||
public static final int MONEY_TYPE = 2;
|
||||
|
||||
private List<ColumnHeaderModel> mColumnHeaderModelList;
|
||||
private List<RowHeaderModel> mRowHeaderModelList;
|
||||
private List<List<CellModel>> mCellModelList;
|
||||
|
||||
public int getCellItemViewType(int column) {
|
||||
|
||||
switch (column) {
|
||||
/*
|
||||
case 5:
|
||||
// 5. column header is gender.
|
||||
return GENDER_TYPE;
|
||||
case 8:
|
||||
// 8. column header is Salary.
|
||||
return MONEY_TYPE;
|
||||
|
||||
*/
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- Each of Column Header -
|
||||
"Id"
|
||||
"Name"
|
||||
"Nickname"
|
||||
"Email"
|
||||
"Birthday"
|
||||
"Gender"
|
||||
"Age"
|
||||
"Job"
|
||||
"Salary"
|
||||
"CreatedAt"
|
||||
"UpdatedAt"
|
||||
"Address"
|
||||
"Zip Code"
|
||||
"Phone"
|
||||
"Fax"
|
||||
*/
|
||||
|
||||
public int getColumnTextAlign(int column) {
|
||||
switch (column) {
|
||||
// Id
|
||||
case 0:
|
||||
return Gravity.CENTER;
|
||||
// Name
|
||||
case 1:
|
||||
return Gravity.LEFT;
|
||||
// Nickname
|
||||
case 2:
|
||||
return Gravity.LEFT;
|
||||
// Email
|
||||
case 3:
|
||||
return Gravity.LEFT;
|
||||
// BirthDay
|
||||
case 4:
|
||||
return Gravity.CENTER;
|
||||
// Gender (Sex)
|
||||
case 5:
|
||||
return Gravity.CENTER;
|
||||
// Age
|
||||
case 6:
|
||||
return Gravity.CENTER;
|
||||
// Job
|
||||
case 7:
|
||||
return Gravity.LEFT;
|
||||
// Salary
|
||||
case 8:
|
||||
return Gravity.CENTER;
|
||||
// CreatedAt
|
||||
case 9:
|
||||
return Gravity.CENTER;
|
||||
// UpdatedAt
|
||||
case 10:
|
||||
return Gravity.CENTER;
|
||||
// Address
|
||||
case 11:
|
||||
return Gravity.LEFT;
|
||||
// Zip Code
|
||||
case 12:
|
||||
return Gravity.RIGHT;
|
||||
// Phone
|
||||
case 13:
|
||||
return Gravity.RIGHT;
|
||||
// Fax
|
||||
case 14:
|
||||
return Gravity.RIGHT;
|
||||
default:
|
||||
return Gravity.CENTER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<ColumnHeaderModel> createColumnHeaderModelList() {
|
||||
List<ColumnHeaderModel> list = new ArrayList<>();
|
||||
|
||||
// Create Column Headers
|
||||
list.add(new ColumnHeaderModel("State"));
|
||||
list.add(new ColumnHeaderModel("Cases"));
|
||||
list.add(new ColumnHeaderModel("Today's Cases"));
|
||||
list.add(new ColumnHeaderModel("Deaths"));
|
||||
list.add(new ColumnHeaderModel("Today's Deaths"));
|
||||
list.add(new ColumnHeaderModel("Active Cases"));
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<List<CellModel>> createCellModelList(List<States> stateList) {
|
||||
List<List<CellModel>> lists = new ArrayList<>();
|
||||
|
||||
// Creating cell model list from User list for Cell Items
|
||||
// In this example, State list is populated from web service
|
||||
|
||||
for (int i = 0; i < stateList.size(); i++) {
|
||||
States state_data = stateList.get(i);
|
||||
|
||||
List<CellModel> list = new ArrayList<>();
|
||||
|
||||
// The order should be same with column header list;
|
||||
list.add(new CellModel("1-" + i, state_data.state)); // "Id"
|
||||
list.add(new CellModel("2-" + i, state_data.cases)); // "Name"
|
||||
list.add(new CellModel("3-" + i, state_data.todayCases)); // "Nickname"
|
||||
list.add(new CellModel("4-" + i, state_data.deaths)); // "Email"
|
||||
list.add(new CellModel("5-" + i, state_data.todayDeaths)); // "BirthDay"
|
||||
list.add(new CellModel("6-" + i, state_data.active));
|
||||
|
||||
// Add
|
||||
lists.add(list);
|
||||
}
|
||||
|
||||
return lists;
|
||||
}
|
||||
|
||||
private List<RowHeaderModel> createRowHeaderList(int size) {
|
||||
List<RowHeaderModel> list = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
// In this example, Row headers just shows the index of the TableView List.
|
||||
list.add(new RowHeaderModel(String.valueOf(i + 1)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public List<ColumnHeaderModel> getColumHeaderModeList() {
|
||||
return mColumnHeaderModelList;
|
||||
}
|
||||
|
||||
public List<RowHeaderModel> getRowHeaderModelList() {
|
||||
return mRowHeaderModelList;
|
||||
}
|
||||
|
||||
public List<List<CellModel>> getCellModelList() {
|
||||
return mCellModelList;
|
||||
}
|
||||
|
||||
|
||||
public void generateListForTableView(List<States> states) {
|
||||
mColumnHeaderModelList = createColumnHeaderModelList();
|
||||
mCellModelList = createCellModelList(states);
|
||||
mRowHeaderModelList = createRowHeaderList(states.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,54 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
|
||||
public class CellViewHolder extends AbstractViewHolder {
|
||||
public final TextView cell_textview;
|
||||
public final LinearLayout cell_container;
|
||||
|
||||
public CellViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
cell_textview = itemView.findViewById(R.id.cell_data);
|
||||
cell_container = itemView.findViewById(R.id.cell_container);
|
||||
}
|
||||
|
||||
public void setCellModel(CellModel p_jModel, int pColumnPosition) {
|
||||
|
||||
// Change textView align by column
|
||||
cell_textview.setGravity(ColumnHeaderViewHolder.COLUMN_TEXT_ALIGNS[pColumnPosition] |
|
||||
Gravity.CENTER_VERTICAL);
|
||||
|
||||
// Set text
|
||||
cell_textview.setText(String.valueOf(p_jModel.getData()));
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
cell_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
cell_textview.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
cell_textview.setTextColor(ContextCompat.getColor(cell_textview.getContext(), R.color
|
||||
.selected_text_color));
|
||||
} else {
|
||||
cell_textview.setTextColor(ContextCompat.getColor(cell_textview.getContext(), R.color
|
||||
.unselected_text_color));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,154 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.ITableView;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder;
|
||||
import com.evrencoskun.tableview.sort.SortState;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
|
||||
public class ColumnHeaderViewHolder extends AbstractSorterViewHolder {
|
||||
final LinearLayout column_header_container;
|
||||
final TextView column_header_textview;
|
||||
final ImageButton column_header_sort_button;
|
||||
final ITableView tableView;
|
||||
|
||||
public ColumnHeaderViewHolder(View itemView, ITableView pTableView) {
|
||||
super(itemView);
|
||||
tableView = pTableView;
|
||||
column_header_textview = itemView.findViewById(R.id.column_header_textView);
|
||||
column_header_container = itemView.findViewById(R.id.column_header_container);
|
||||
column_header_sort_button = itemView.findViewById(R.id.column_header_sort_imageButton);
|
||||
|
||||
// Set click listener to the sort button
|
||||
column_header_sort_button.setOnClickListener(mSortButtonClickListener);
|
||||
}
|
||||
|
||||
public void setColumnHeaderModel(ColumnHeaderModel pColumnHeaderModel, int pColumnPosition) {
|
||||
|
||||
// Change alignment of textView
|
||||
column_header_textview.setGravity(COLUMN_TEXT_ALIGNS[pColumnPosition] | Gravity
|
||||
.CENTER_VERTICAL);
|
||||
|
||||
// Set text data
|
||||
column_header_textview.setText(pColumnHeaderModel.getData());
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
column_header_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
column_header_textview.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
int nBackgroundColorId;
|
||||
int nForegroundColorId;
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
nBackgroundColorId = R.color.selected_background_color;
|
||||
nForegroundColorId = R.color.selected_text_color;
|
||||
|
||||
} else if (p_nSelectionState == SelectionState.UNSELECTED) {
|
||||
nBackgroundColorId = R.color.unselected_header_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
|
||||
} else { // SelectionState.SHADOWED
|
||||
|
||||
nBackgroundColorId = R.color.shadow_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
}
|
||||
|
||||
column_header_container.setBackgroundColor(ContextCompat.getColor(column_header_container
|
||||
.getContext(), nBackgroundColorId));
|
||||
column_header_textview.setTextColor(ContextCompat.getColor(column_header_container
|
||||
.getContext(), nForegroundColorId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortingStatusChanged(SortState pSortState) {
|
||||
super.onSortingStatusChanged(pSortState);
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
column_header_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
controlSortState(pSortState);
|
||||
|
||||
column_header_textview.requestLayout();
|
||||
column_header_sort_button.requestLayout();
|
||||
column_header_container.requestLayout();
|
||||
itemView.requestLayout();
|
||||
}
|
||||
|
||||
private void controlSortState(SortState pSortState) {
|
||||
if (pSortState == SortState.ASCENDING) {
|
||||
column_header_sort_button.setVisibility(View.VISIBLE);
|
||||
column_header_sort_button.setImageResource(R.drawable.ic_down);
|
||||
|
||||
} else if (pSortState == SortState.DESCENDING) {
|
||||
column_header_sort_button.setVisibility(View.VISIBLE);
|
||||
column_header_sort_button.setImageResource(R.drawable.ic_up);
|
||||
} else {
|
||||
column_header_sort_button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private View.OnClickListener mSortButtonClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (getSortState() == SortState.ASCENDING) {
|
||||
tableView.sortColumn(getAdapterPosition(), SortState.DESCENDING);
|
||||
} else if (getSortState() == SortState.DESCENDING) {
|
||||
tableView.sortColumn(getAdapterPosition(), SortState.ASCENDING);
|
||||
} else {
|
||||
// Default one
|
||||
tableView.sortColumn(getAdapterPosition(), SortState.DESCENDING);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static final int[] COLUMN_TEXT_ALIGNS = {
|
||||
// Id
|
||||
Gravity.CENTER,
|
||||
// Name
|
||||
Gravity.LEFT,
|
||||
// Nickname
|
||||
Gravity.LEFT,
|
||||
// Email
|
||||
Gravity.LEFT,
|
||||
// BirthDay
|
||||
Gravity.CENTER,
|
||||
// Gender (Sex)
|
||||
Gravity.CENTER,
|
||||
// Age
|
||||
Gravity.CENTER,
|
||||
// Job
|
||||
Gravity.LEFT,
|
||||
// Salary
|
||||
Gravity.CENTER,
|
||||
// CreatedAt
|
||||
Gravity.CENTER,
|
||||
// UpdatedAt
|
||||
Gravity.CENTER,
|
||||
// Address
|
||||
Gravity.LEFT,
|
||||
// Zip Code
|
||||
Gravity.RIGHT,
|
||||
// Phone
|
||||
Gravity.RIGHT,
|
||||
// Fax
|
||||
Gravity.RIGHT};
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
|
||||
import org.fabiomsr.moneytextview.MoneyTextView;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 22.12.2017.
|
||||
*/
|
||||
|
||||
public class MoneyCellViewHolder extends AbstractViewHolder {
|
||||
public final MoneyTextView cell_textview;
|
||||
public final LinearLayout cell_container;
|
||||
|
||||
public MoneyCellViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
cell_textview = itemView.findViewById(R.id.money_cell_data);
|
||||
cell_container = itemView.findViewById(R.id.cell_container);
|
||||
}
|
||||
|
||||
public void setCellModel(CellModel p_jModel) {
|
||||
|
||||
// Set text
|
||||
cell_textview.setAmount(Float.parseFloat((String) p_jModel.getData()));
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
cell_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
cell_textview.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
changeColorOfMoneyTextView(R.color.selected_text_color);
|
||||
} else {
|
||||
changeColorOfMoneyTextView(R.color.unselected_text_color);
|
||||
}
|
||||
}
|
||||
|
||||
private void changeColorOfMoneyTextView(@ColorRes int id) {
|
||||
int color = ContextCompat.getColor(cell_textview.getContext(), id);
|
||||
|
||||
cell_textview.setBaseColor(color);
|
||||
cell_textview.setDecimalsColor(color);
|
||||
cell_textview.setSymbolColor(color);
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
|
||||
public class RowHeaderViewHolder extends AbstractViewHolder {
|
||||
public final TextView row_header_textview;
|
||||
|
||||
public RowHeaderViewHolder(View p_jItemView) {
|
||||
super(p_jItemView);
|
||||
row_header_textview = p_jItemView.findViewById(R.id.row_header_textview);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
int nBackgroundColorId;
|
||||
int nForegroundColorId;
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
nBackgroundColorId = R.color.selected_background_color;
|
||||
nForegroundColorId = R.color.selected_text_color;
|
||||
|
||||
} else if (p_nSelectionState == SelectionState.UNSELECTED) {
|
||||
nBackgroundColorId = R.color.unselected_header_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
|
||||
} else { // SelectionState.SHADOWED
|
||||
|
||||
nBackgroundColorId = R.color.shadow_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
}
|
||||
|
||||
itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(),
|
||||
nBackgroundColorId));
|
||||
row_header_textview.setTextColor(ContextCompat.getColor(row_header_textview.getContext(),
|
||||
nForegroundColorId));
|
||||
}
|
||||
}
|
32
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/CellModel.java
Executable file
32
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/CellModel.java
Executable file
@@ -0,0 +1,32 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.model;
|
||||
|
||||
import com.evrencoskun.tableview.sort.ISortableModel;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class CellModel implements ISortableModel {
|
||||
private String mId;
|
||||
private Object mData;
|
||||
|
||||
public CellModel(String pId, Object mData) {
|
||||
this.mId = pId;
|
||||
this.mData = mData;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContent() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.model;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class ColumnHeaderModel {
|
||||
|
||||
private String mData;
|
||||
|
||||
public ColumnHeaderModel(String mData) {
|
||||
this.mData = mData;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return mData;
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.model;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class RowHeaderModel {
|
||||
private String mData;
|
||||
|
||||
public RowHeaderModel(String mData) {
|
||||
this.mData = mData;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return mData;
|
||||
}
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.popup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import com.evrencoskun.tableview.ITableView;
|
||||
import com.evrencoskun.tableview.sort.SortState;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 26.12.2017.
|
||||
*/
|
||||
|
||||
public class ColumnHeaderLongPressPopup extends PopupMenu implements PopupMenu
|
||||
.OnMenuItemClickListener {
|
||||
private static final String LOG_TAG = ColumnHeaderLongPressPopup.class.getSimpleName();
|
||||
|
||||
// Sort states
|
||||
private static final int ASCENDING = 1;
|
||||
private static final int DESCENDING = 2;
|
||||
private static final int CLEAR = 3;
|
||||
// Test menu items for showing / hiding row
|
||||
private static final int ROW_HIDE = 4;
|
||||
private static final int ROW_SHOW = 3;
|
||||
|
||||
//
|
||||
private static final int TEST_ROW_INDEX = 4;
|
||||
|
||||
|
||||
private ColumnHeaderViewHolder m_iViewHolder;
|
||||
private ITableView m_iTableView;
|
||||
private Context mContext;
|
||||
private int mXPosition;
|
||||
|
||||
public ColumnHeaderLongPressPopup(ColumnHeaderViewHolder p_iViewHolder, ITableView
|
||||
p_jTableView) {
|
||||
super(p_iViewHolder.itemView.getContext(), p_iViewHolder.itemView);
|
||||
this.m_iViewHolder = p_iViewHolder;
|
||||
this.m_iTableView = p_jTableView;
|
||||
this.mContext = p_iViewHolder.itemView.getContext();
|
||||
this.mXPosition = m_iViewHolder.getAdapterPosition();
|
||||
|
||||
// find the view holder
|
||||
m_iViewHolder = (ColumnHeaderViewHolder) m_iTableView.getColumnHeaderRecyclerView()
|
||||
.findViewHolderForAdapterPosition(mXPosition);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
createMenuItem();
|
||||
changeMenuItemVisibility();
|
||||
|
||||
this.setOnMenuItemClickListener(this);
|
||||
}
|
||||
|
||||
private void createMenuItem() {
|
||||
this.getMenu().add(Menu.NONE, ASCENDING, 0, mContext.getString(R.string.sort_ascending));
|
||||
this.getMenu().add(Menu.NONE, DESCENDING, 1, mContext.getString(R.string.sort_descending));
|
||||
this.getMenu().add(Menu.NONE, ROW_HIDE, 2, mContext.getString(R.string.row_hide));
|
||||
this.getMenu().add(Menu.NONE, ROW_SHOW, 3, mContext.getString(R.string.row_show));
|
||||
// add new one ...
|
||||
|
||||
}
|
||||
|
||||
private void changeMenuItemVisibility() {
|
||||
// Determine which one shouldn't be visible
|
||||
SortState sortState = m_iTableView.getSortingStatus(mXPosition);
|
||||
if (sortState == SortState.UNSORTED) {
|
||||
// Show others
|
||||
} else if (sortState == SortState.DESCENDING) {
|
||||
// Hide DESCENDING menu item
|
||||
getMenu().getItem(1).setVisible(false);
|
||||
} else if (sortState == SortState.ASCENDING) {
|
||||
// Hide ASCENDING menu item
|
||||
getMenu().getItem(0).setVisible(false);
|
||||
}
|
||||
|
||||
// Control whether 5. row is visible or not.
|
||||
if (m_iTableView.isRowVisible(TEST_ROW_INDEX)) {
|
||||
// Show row menu item will be invisible
|
||||
getMenu().getItem(3).setVisible(false);
|
||||
} else {
|
||||
// Hide row menu item will be invisible
|
||||
getMenu().getItem(2).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||
// Note: item id is index of menu item..
|
||||
|
||||
switch (menuItem.getItemId()) {
|
||||
case ASCENDING:
|
||||
m_iTableView.sortColumn(mXPosition, SortState.ASCENDING);
|
||||
break;
|
||||
case DESCENDING:
|
||||
m_iTableView.sortColumn(mXPosition, SortState.DESCENDING);
|
||||
break;
|
||||
case ROW_HIDE:
|
||||
// Hide 5. row for testing process
|
||||
// index starts from 0. That's why TEST_ROW_INDEX is 4.
|
||||
m_iTableView.hideRow(TEST_ROW_INDEX);
|
||||
break;
|
||||
case ROW_SHOW:
|
||||
// Show 5. row for testing process
|
||||
// index starts from 0. That's why TEST_ROW_INDEX is 4.
|
||||
m_iTableView.showRow(TEST_ROW_INDEX);
|
||||
break;
|
||||
}
|
||||
|
||||
// Recalculate of the width values of the columns
|
||||
m_iTableView.remeasureColumnWidth(mXPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourcountriesViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
private final LiveData<List<YesCountries>> mYesCountriesData;
|
||||
|
||||
public YourcountriesViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
this.mYesCountriesData = mRepository.getYesCountriesList();
|
||||
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public LiveData<List<YesCountries>> getYesCountriesList() {
|
||||
return mYesCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourrealcountryViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
private final LiveData<List<YesCountries>> mYesCountriesData;
|
||||
|
||||
public YourrealcountryViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
this.mYesCountriesData = mRepository.getYesCountriesList();
|
||||
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public LiveData<List<YesCountries>> getYesCountriesList() {
|
||||
return mYesCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesStates;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourstateViewModel extends ViewModel {
|
||||
|
||||
private final StateRepository mRepository;
|
||||
private final LiveData<List<States>> mStatesData;
|
||||
private final LiveData<List<YesStates>> mYesStatesData;
|
||||
|
||||
public YourstateViewModel(StateRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mStatesData = mRepository.getStatesList();
|
||||
this.mYesStatesData = mRepository.getYesStatesList();
|
||||
|
||||
}
|
||||
|
||||
public LiveData<List<States>> getStatesList() {
|
||||
return mStatesData;
|
||||
}
|
||||
|
||||
public LiveData<List<YesStates>> getYesStatesList() {
|
||||
return mYesStatesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.WorldRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
public class YourworldViewModel extends ViewModel {
|
||||
|
||||
private final WorldRepository mRepository;
|
||||
private final LiveData<World> mWorldData;
|
||||
private final LiveData<YesWorld> mYesWorldData;
|
||||
|
||||
public YourworldViewModel(WorldRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mWorldData = mRepository.getWorld();
|
||||
this.mYesWorldData = mRepository.getYesWorld();
|
||||
}
|
||||
|
||||
public LiveData<World> getWorld() {
|
||||
return mWorldData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
|
||||
public LiveData<YesWorld> getYesWorld() {
|
||||
return mYesWorldData;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link CountriesRepository}
|
||||
*/
|
||||
public class yourCountriesViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final CountriesRepository countriesRepository;
|
||||
|
||||
public yourCountriesViewModelFactory(CountriesRepository countriesRepository) {
|
||||
this.countriesRepository = countriesRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourcountriesViewModel(countriesRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link StateRepository}
|
||||
*/
|
||||
public class yourStateViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final StateRepository stateRepository;
|
||||
|
||||
public yourStateViewModelFactory(StateRepository stateRepository) {
|
||||
this.stateRepository = stateRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourstateViewModel(stateRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.WorldRepository;
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link StateRepository}
|
||||
*/
|
||||
public class yourWorldViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final WorldRepository worldRepository;
|
||||
|
||||
public yourWorldViewModelFactory(WorldRepository worldRepository) {
|
||||
this.worldRepository = worldRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourworldViewModel(worldRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link CountriesRepository}
|
||||
*/
|
||||
public class yourrealcountryViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final CountriesRepository countriesRepository;
|
||||
|
||||
public yourrealcountryViewModelFactory(CountriesRepository countriesRepository) {
|
||||
this.countriesRepository = countriesRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourrealcountryViewModel(countriesRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
package com.josh.trackcovid19v2.ui.yourcountries;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.evrencoskun.tableview.TableView;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.tableview.CountriesTableAdapter;
|
||||
import com.josh.trackcovid19v2.ui.tableview.MyTableViewListener;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourcountriesViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourCountriesViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
|
||||
public class YourcountriesFragment extends Fragment {
|
||||
|
||||
|
||||
private YourcountriesViewModel yourcountryViewModel;
|
||||
private TableView mTableView;
|
||||
private CountriesTableAdapter mTableAdapter;
|
||||
private ProgressBar mProgressBar;
|
||||
private YourcountriesViewModel vYourcountriesViewModel;
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
/*
|
||||
homeViewModel =
|
||||
ViewModelProviders.of(this).get(HomeViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_yourworld, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_home);
|
||||
homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
}
|
||||
});
|
||||
return root;
|
||||
|
||||
*/
|
||||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_yourcountry, container, false);
|
||||
|
||||
mProgressBar = view.findViewById(R.id.countries_progressBar);
|
||||
|
||||
mTableView = view.findViewById(R.id.countries_TableView);
|
||||
|
||||
initializeTableView(mTableView);
|
||||
|
||||
|
||||
// initialize ViewModel
|
||||
yourCountriesViewModelFactory factory = InjectorUtils.getCountriesViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourcountriesViewModel = ViewModelProviders.of(this, factory).get(YourcountriesViewModel.class);
|
||||
|
||||
vYourcountriesViewModel.getCountriesList().observe(this, countries -> {
|
||||
|
||||
if(countries != null && countries.size()>0){
|
||||
// set the list on TableViewModel
|
||||
mTableAdapter.setCountriesList(countries);
|
||||
|
||||
hideProgressBar();
|
||||
}
|
||||
});
|
||||
|
||||
// Let's post a request to get the User data from a web server.
|
||||
postRequest();
|
||||
|
||||
return view;
|
||||
|
||||
}
|
||||
|
||||
private void initializeTableView(TableView tableView){
|
||||
|
||||
// Create TableView Adapter
|
||||
mTableAdapter = new CountriesTableAdapter(getContext());
|
||||
tableView.setAdapter(mTableAdapter);
|
||||
|
||||
// Create listener
|
||||
tableView.setTableViewListener(new MyTableViewListener(tableView));
|
||||
}
|
||||
|
||||
|
||||
private void postRequest(){
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourcountriesViewModel.postRequest(serviceRequest);
|
||||
|
||||
showProgressBar();
|
||||
}
|
||||
|
||||
|
||||
public void showProgressBar() {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mTableView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
public void hideProgressBar() {
|
||||
mProgressBar.setVisibility(View.INVISIBLE);
|
||||
mTableView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html){
|
||||
if(html == null){
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,29 @@
|
||||
package com.josh.trackcovid19v2.ui.yourcountries;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourcountriesViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
|
||||
public YourcountriesViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,262 @@
|
||||
package com.josh.trackcovid19v2.ui.yourrealcountry;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourcountriesViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourrealcountryViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourCountriesViewModelFactory;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourrealcountryViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class YourrealcountryFragment extends Fragment {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private YourrealcountryViewModel vYourrealcountryViewModel;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_yourrealcountry, container, false);
|
||||
SwipeRefreshLayout mSwipeRefreshLayout = view.findViewById(R.id.swiperefresh);
|
||||
final int[] rememberLocation = {-1};
|
||||
final int[] j = {0};
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Log.v("REFRESHING", "************** APP - SWIPE REFRESH EVENT TRIGGERED!!!!!");
|
||||
|
||||
postRequest();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override public void run() {
|
||||
// Stop animation (This will be after 3 seconds)
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, 1000); // Delay in millis
|
||||
}
|
||||
});
|
||||
|
||||
yourrealcountryViewModelFactory factory = InjectorUtils.getRealCountryViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourrealcountryViewModel = ViewModelProviders.of(this, factory).get(YourrealcountryViewModel.class);
|
||||
|
||||
vYourrealcountryViewModel.getCountriesList().observe(this, countries -> {
|
||||
|
||||
if (countries != null && countries.size() > 0) {
|
||||
// set the list on TableViewModel
|
||||
|
||||
String[] country_list = new String[countries.size()];
|
||||
|
||||
for (int i = 0; i < countries.size(); i++) {
|
||||
country_list[i] = countries.get(i).country;
|
||||
if (countries.get(i).country.equalsIgnoreCase("USA")) {
|
||||
j[0] = i;
|
||||
}
|
||||
}
|
||||
final int[] cases = {0};
|
||||
final int[] ycases = {0};
|
||||
final int[] yACases = {0};
|
||||
final int[] ACases = {0};
|
||||
final int[] yRecovered = {0};
|
||||
final int[] recovered = {0};
|
||||
final int[] yDeaths = {0};
|
||||
final int[] Toddeaths = {0};
|
||||
final int[] critical = {0};
|
||||
final int[] yCritical = {0};
|
||||
final int[] yTests = {0};
|
||||
final int[] tests = {0};
|
||||
|
||||
|
||||
vYourrealcountryViewModel.getYesCountriesList().observe(this, yescountries -> {
|
||||
if (yescountries != null && yescountries.size() > 0) {
|
||||
String[] yescountry_list = new String[yescountries.size()];
|
||||
|
||||
//String[] users = { "Suresh Dasari", "Trishika Dasari", "Rohini Alavala", "Praveen Kumar", "Madhav Sai" };
|
||||
Spinner spin = view.findViewById(R.id.spinner1);
|
||||
final TextView textView = view.findViewById(R.id.text_totalCasesData);
|
||||
final TextView textView1 = view.findViewById(R.id.text_activeCasesData);
|
||||
final TextView textView2 = view.findViewById(R.id.text_RecoveredData);
|
||||
final TextView textView3 = view.findViewById(R.id.text_deathsData);
|
||||
final TextView textView4 = view.findViewById(R.id.text_CriticalData);
|
||||
final TextView textView5 = view.findViewById(R.id.text_CriticalDataIncriment);
|
||||
final TextView textView6 = view.findViewById(R.id.text_deathsDataIncriment);
|
||||
final TextView textView7 = view.findViewById(R.id.text_RealRecoveredDataIncriment);
|
||||
final TextView textView8 = view.findViewById(R.id.text_dailyIncriment);
|
||||
final TextView textView9 = view.findViewById(R.id.text_activeCasesIncriment);
|
||||
final TextView textView10 = view.findViewById(R.id.textView2);
|
||||
final TextView textView11 = view.findViewById(R.id.text_totalTestsData);
|
||||
final TextView textView12 = view.findViewById(R.id.text_testsPerOneMillionData);
|
||||
final TextView textView13 = view.findViewById(R.id.text_updated);
|
||||
final ImageView imageView = view.findViewById(R.id.htmlImageGetter);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.my_spinner_style, country_list);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spin.setAdapter(adapter);
|
||||
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Picasso.get().load(countries.get(position).flag).into(imageView);
|
||||
Log.d("foo", country_list[position]);
|
||||
cases[0] = countries.get(position).cases;
|
||||
ycases[0] = yescountries.get(position).cases;
|
||||
ACases[0] = countries.get(position).active;
|
||||
yACases[0] = yescountries.get(position).active;
|
||||
recovered[0] = countries.get(position).recovered;
|
||||
yRecovered[0] = yescountries.get(position).recovered;
|
||||
Toddeaths[0] = countries.get(position).deaths;
|
||||
yDeaths[0] = yescountries.get(position).deaths;
|
||||
recovered[0] = countries.get(position).recovered;
|
||||
yRecovered[0] = yescountries.get(position).recovered;
|
||||
tests[0] = countries.get(position).tests;
|
||||
yTests[0] = yescountries.get(position).tests;
|
||||
critical[0] = countries.get(position).critical;
|
||||
yCritical[0] = yescountries.get(position).critical;
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
textView10.setText(Html.fromHtml("<b>Pick a country from the dropdown below</b>"));
|
||||
String totalCasesWithCommas = numberFormat.format(countries.get(position).cases);
|
||||
String activeCasesWithCommas = numberFormat.format(countries.get(position).active);
|
||||
String recoveredWithCommas = numberFormat.format(countries.get(position).recovered);
|
||||
String deathWithCommas = numberFormat.format(countries.get(position).deaths);
|
||||
String criticalWithCommas = numberFormat.format(countries.get(position).critical);
|
||||
String ToddeathsWithCommas = numberFormat.format(countries.get(position).todayDeaths);
|
||||
String TodCasesWithCommas = numberFormat.format(countries.get(position).todayCases);
|
||||
String testsWithCommas = numberFormat.format(countries.get(position).tests);
|
||||
String testsMilWithcommas = numberFormat.format(countries.get(position).testsPerMillion);
|
||||
Date date = new Date(countries.get(position).updated);
|
||||
textView13.setText(Html.fromHtml("Updated on "+ date));
|
||||
textView.setText(Html.fromHtml("<center><b>" + totalCasesWithCommas + "</b></center>"));
|
||||
textView3.setText(Html.fromHtml("<b>" + deathWithCommas + "</b>"));
|
||||
textView2.setText(Html.fromHtml("<b>" + recoveredWithCommas + "</b>"));
|
||||
textView1.setText(Html.fromHtml("<b>" + activeCasesWithCommas + "</b>"));
|
||||
textView4.setText(Html.fromHtml("<b>" + criticalWithCommas + "</b>"));
|
||||
textView6.setText(Html.fromHtml("<b>" + ToddeathsWithCommas + "</b>"));
|
||||
textView8.setText(Html.fromHtml("<b>" + TodCasesWithCommas + "</b>"));
|
||||
textView11.setText(Html.fromHtml("<b>" + testsWithCommas + "</b>"));
|
||||
textView12.setText(Html.fromHtml("<b>" + testsMilWithcommas + "</b>"));
|
||||
String dailyActWithCommas = numberFormat.format(ACases[0] - yACases[0]);
|
||||
String dailyRecoveredWithCommas = numberFormat.format(recovered[0] - yRecovered[0]);
|
||||
String dailyTestWithCommas = numberFormat.format(tests[0] - yTests[0]);
|
||||
String todCritWithCommas = numberFormat.format(critical[0] - yCritical[0]);
|
||||
if ((cases[0] - ycases[0]) >= 0) {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "+" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
} else {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "-" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
if ((ACases[0] - yACases[0]) >= 0) {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "+" + dailyActWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((recovered[0] - yRecovered[0]) >= 0) {
|
||||
textView7.setText(Html.fromHtml("<b><i>" + "+" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView7.setText(Html.fromHtml("<b><i>" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((Toddeaths[0] - yDeaths[0]) >= 0) {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((critical[0] - yCritical[0]) >= 0) {
|
||||
textView5.setText(Html.fromHtml("<b><i>" + "+" + todCritWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView5.setText(Html.fromHtml("<b><i>" + todCritWithCommas + "</i></b>"));
|
||||
}
|
||||
/*
|
||||
if((Toddeaths[0] - yDeaths[0]) >= 0){
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "-" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken inside one." + ", name: "+"not found at all");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken outside one." + ", name: "+"not found at all");
|
||||
}
|
||||
});
|
||||
postRequest();
|
||||
return view;
|
||||
//return inflater.inflate(R.layout.fragment_yourrealcountry,container,false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html) {
|
||||
if (html == null) {
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
|
||||
private void postRequest() {
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourrealcountryViewModel.postRequest(serviceRequest);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.josh.trackcovid19v2.ui.yourrealcountry;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourrealcountryViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
|
||||
public YourrealcountryViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,228 @@
|
||||
package com.josh.trackcovid19v2.ui.yourstate;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourstateViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourStateViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class YourstateFragment extends Fragment {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private YourstateViewModel vYourstateViewModel;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html) {
|
||||
if (html == null) {
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_yourstate, container, false);
|
||||
SwipeRefreshLayout mSwipeRefreshLayout = view.findViewById(R.id.swiperefresh);
|
||||
final int[] rememberLocation = {-1};
|
||||
final int[] j = {0};
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Log.v("REFRESHING", "************** APP - SWIPE REFRESH EVENT TRIGGERED!!!!!");
|
||||
|
||||
postRequest();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Stop animation (This will be after 3 seconds)
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, 1000); // Delay in millis
|
||||
}
|
||||
});
|
||||
|
||||
yourStateViewModelFactory factory = InjectorUtils.getStateViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourstateViewModel = ViewModelProviders.of(this, factory).get(YourstateViewModel.class);
|
||||
|
||||
vYourstateViewModel.getStatesList().observe(this, states -> {
|
||||
|
||||
if (states != null && states.size() > 0) {
|
||||
// set the list on TableViewModel
|
||||
|
||||
String[] state_list = new String[states.size()];
|
||||
|
||||
for (int i = 0; i < states.size(); i++) {
|
||||
state_list[i] = states.get(i).state;
|
||||
if (states.get(i).state.equalsIgnoreCase("New York")) {
|
||||
j[0] = i;
|
||||
}
|
||||
}
|
||||
final int[] cases = {0};
|
||||
final int[] ycases = {0};
|
||||
final int[] yACases = {0};
|
||||
final int[] ACases = {0};
|
||||
final int[] yDeaths = {0};
|
||||
final int[] Toddeaths = {0};
|
||||
final int[] yTests = {0};
|
||||
final int[] tests = {0};
|
||||
|
||||
|
||||
vYourstateViewModel.getYesStatesList().observe(this, yesstates -> {
|
||||
if (yesstates != null && yesstates.size() > 0) {
|
||||
String[] yesstate_list = new String[yesstates.size()];
|
||||
|
||||
//String[] users = { "Suresh Dasari", "Trishika Dasari", "Rohini Alavala", "Praveen Kumar", "Madhav Sai" };
|
||||
Spinner spin = view.findViewById(R.id.spinner1);
|
||||
final TextView textView = view.findViewById(R.id.text_totalCasesData);
|
||||
final TextView textView1 = view.findViewById(R.id.text_activeCasesData);
|
||||
final TextView textView2 = view.findViewById(R.id.text_RecoveredData);
|
||||
final TextView textView3 = view.findViewById(R.id.text_deathsData);
|
||||
final TextView textView4 = view.findViewById(R.id.text_CriticalData);
|
||||
final TextView textView5 = view.findViewById(R.id.text_CriticalDataIncriment);
|
||||
final TextView textView6 = view.findViewById(R.id.text_deathsDataIncriment);
|
||||
final TextView textView7 = view.findViewById(R.id.text_RealRecoveredDataIncriment);
|
||||
final TextView textView8 = view.findViewById(R.id.text_dailyIncriment);
|
||||
final TextView textView9 = view.findViewById(R.id.text_activeCasesIncriment);
|
||||
final TextView textView10 = view.findViewById(R.id.textView2);
|
||||
final TextView textView11 = view.findViewById(R.id.text_totalTestsData);
|
||||
final TextView textView12 = view.findViewById(R.id.text_testsPerOneMillionData);
|
||||
final TextView textView13 = view.findViewById(R.id.text_updated);
|
||||
final ImageView imageView = view.findViewById(R.id.htmlImageGetter);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.my_spinner_style, state_list);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spin.setAdapter(adapter);
|
||||
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log.d("foo", state_list[position]);
|
||||
cases[0] = states.get(position).cases;
|
||||
ycases[0] = yesstates.get(position).cases;
|
||||
ACases[0] = states.get(position).active;
|
||||
yACases[0] = yesstates.get(position).active;
|
||||
Toddeaths[0] = states.get(position).deaths;
|
||||
yDeaths[0] = yesstates.get(position).deaths;
|
||||
tests[0] = states.get(position).tests;
|
||||
yTests[0] = yesstates.get(position).tests;
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
//setData(vYourworldViewModel,world);
|
||||
textView10.setText(Html.fromHtml("<b>Pick a state from the dropdown below</b>"));
|
||||
String totalCasesWithCommas = numberFormat.format(states.get(position).cases);
|
||||
String activeCasesWithCommas = numberFormat.format(states.get(position).active);
|
||||
String deathWithCommas = numberFormat.format(states.get(position).deaths);
|
||||
String ToddeathsWithCommas = numberFormat.format(states.get(position).todayDeaths);
|
||||
String TodCasesWithCommas = numberFormat.format(states.get(position).todayCases);
|
||||
String testsWithCommas = numberFormat.format(states.get(position).tests);
|
||||
String testsMilWithcommas = numberFormat.format(states.get(position).testsPerMillion);
|
||||
textView.setText(Html.fromHtml("<center><b>" + totalCasesWithCommas + "</b></center>"));
|
||||
textView3.setText(Html.fromHtml("<b>" + deathWithCommas + "</b>"));
|
||||
textView1.setText(Html.fromHtml("<b>" + activeCasesWithCommas + "</b>"));
|
||||
textView6.setText(Html.fromHtml("<b>" + ToddeathsWithCommas + "</b>"));
|
||||
textView8.setText(Html.fromHtml("<b>" + TodCasesWithCommas + "</b>"));
|
||||
textView11.setText(Html.fromHtml("<b>" + testsWithCommas + "</b>"));
|
||||
textView12.setText(Html.fromHtml("<b>" + testsMilWithcommas + "</b>"));
|
||||
String dailyActWithCommas = numberFormat.format(ACases[0] - yACases[0]);
|
||||
String dailyTestWithCommas = numberFormat.format(tests[0] - yTests[0]);
|
||||
if ((cases[0] - ycases[0]) >= 0) {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "+" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
} else {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "-" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
if ((ACases[0] - yACases[0]) >= 0) {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "+" + dailyActWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((Toddeaths[0] - yDeaths[0]) >= 0) {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
/*
|
||||
if((Toddeaths[0] - yDeaths[0]) >= 0){
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "-" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken inside one." + ", name: "+"not found at all");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken outside one." + ", name: "+"not found at all");
|
||||
}
|
||||
});
|
||||
postRequest();
|
||||
return view;
|
||||
}
|
||||
|
||||
private void postRequest() {
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourstateViewModel.postRequest(serviceRequest);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.josh.trackcovid19v2.ui.yourstate;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourstateViewModel extends ViewModel {
|
||||
|
||||
private final StateRepository mRepository;
|
||||
private final LiveData<List<States>> mStatesData;
|
||||
|
||||
public YourstateViewModel(StateRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mStatesData = mRepository.getStatesList();
|
||||
}
|
||||
|
||||
public LiveData<List<States>> getStatesList() {
|
||||
return mStatesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
}
|
||||
}
|
245
app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldFragment.java
Executable file
245
app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldFragment.java
Executable file
@@ -0,0 +1,245 @@
|
||||
package com.josh.trackcovid19v2.ui.yourworld;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ClipDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourWorldViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class YourworldFragment extends Fragment {
|
||||
|
||||
private static YourworldFragment BdTimeUtils;
|
||||
private YourworldViewModel yourworldViewModel;
|
||||
private com.josh.trackcovid19v2.ui.viewmodel.YourworldViewModel vYourworldViewModel;
|
||||
private static DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_yourworld, container, false);
|
||||
SwipeRefreshLayout mSwipeRefreshLayout = view.findViewById(R.id.swiperefresh);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Log.v("REFRESHING", "************** APP - SWIPE REFRESH EVENT TRIGGERED!!!!!");
|
||||
postRequest();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override public void run() {
|
||||
// Stop animation (This will be after 3 seconds)
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, 1000); // Delay in millis
|
||||
}
|
||||
});
|
||||
yourWorldViewModelFactory factory = InjectorUtils.getWorldViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourworldViewModel = ViewModelProviders.of(this, factory).get(com.josh.trackcovid19v2.ui.viewmodel.YourworldViewModel.class);
|
||||
|
||||
final int[] cases = {0};
|
||||
final int[] ycases = {0};
|
||||
final int[] yACases = {0};
|
||||
final int[] ACases = {0};
|
||||
final int[] yRecovered = {0};
|
||||
final int[] recovered = {0};
|
||||
final int[] yDeaths = {0};
|
||||
final int[] Toddeaths = {0};
|
||||
vYourworldViewModel.getWorld().observe(this, world -> {
|
||||
|
||||
if (world != null) {
|
||||
|
||||
Log.d("foooo", String.valueOf(world.cases));
|
||||
|
||||
|
||||
cases[0] = world.cases;
|
||||
ACases[0] = world.active;
|
||||
recovered[0] = world.recovered;
|
||||
Toddeaths[0] = world.deaths;
|
||||
|
||||
Log.d("foooo", "I am here");
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
//setData(vYourworldViewModel,world);
|
||||
TextView textView = view.findViewById(R.id.text_totalCasesData);
|
||||
TextView textViewa = view.findViewById(R.id.text_totalCasesName);
|
||||
TextView textView2 = view.findViewById(R.id.text_deathsData);
|
||||
TextView textView3 = view.findViewById(R.id.text_recoveredData);
|
||||
//unneeded for now
|
||||
TextView textView4 = view.findViewById(R.id.text_updated);
|
||||
TextView textView5 = view.findViewById(R.id.text_activeCasesData);
|
||||
TextView textView6 = view.findViewById(R.id.text_affectedCountriesData);
|
||||
TextView textView7 = view.findViewById(R.id.textView2);
|
||||
TextView textView123 = view.findViewById(R.id.textView4);
|
||||
|
||||
//commas to large numbers
|
||||
String totalCasesWithCommas = numberFormat.format(world.cases);
|
||||
String activeCasesWithCommas = numberFormat.format(world.active);
|
||||
String recoveredWithCommas = numberFormat.format(world.recovered);
|
||||
String deathWithCommas = numberFormat.format(world.deaths);
|
||||
//yesworld data goes above
|
||||
String affectedCountriesData = Integer.toString(world.affectedCountries);
|
||||
Date date = new Date(world.updated);
|
||||
textView.setText(Html.fromHtml("<center><b>" + totalCasesWithCommas + "</b></center>"));
|
||||
textViewa.setText(Html.fromHtml("Total Confirmed Cases"));
|
||||
textView7.setText(Html.fromHtml("<b>COVID-19 Statistics</b>"));
|
||||
textView2.setText(Html.fromHtml("<b>" + deathWithCommas + "</b>"));
|
||||
textView3.setText(Html.fromHtml("<b>" + recoveredWithCommas + "</b>"));
|
||||
textView5.setText(Html.fromHtml("<b>" + activeCasesWithCommas + "</b>"));
|
||||
textView6.setText(Html.fromHtml("<b><sup>" + affectedCountriesData + "</sup>" + "/<sub>251</sub></b>"));
|
||||
textView4.setText(Html.fromHtml("Updated on "+ date));
|
||||
ImageView img1 = view.findViewById(R.id.image_level);
|
||||
double recov = world.recovered;
|
||||
double tcases = world.cases;
|
||||
double percent = (recov/tcases)*100;
|
||||
String percentlegible = df.format(percent);
|
||||
textView123.setText(Html.fromHtml("<b><i>" + percentlegible + "%</i></b>"));
|
||||
Log.d("dfdF", String.valueOf(world.recovered));
|
||||
Log.d("dfdF", String.valueOf(world.cases));
|
||||
Log.d("dfdF", String.valueOf(percent));
|
||||
int x= (int)percent;
|
||||
ClipDrawable drawable = (ClipDrawable) img1.getDrawable();
|
||||
drawable.setLevel(100 * x);
|
||||
}
|
||||
vYourworldViewModel.getYesWorld().observe(this, yesworld -> {
|
||||
|
||||
if (yesworld != null) {
|
||||
|
||||
Log.d("foooo", String.valueOf(yesworld.cases));
|
||||
ycases[0] = yesworld.cases;
|
||||
yACases[0] = yesworld.active;
|
||||
yRecovered[0] = yesworld.recovered;
|
||||
yDeaths[0] = yesworld.deaths;
|
||||
|
||||
Log.d("foooo", "I am in yesworld here");
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
TextView textView8 = view.findViewById(R.id.text_dailyIncriment);
|
||||
TextView textView9 = view.findViewById(R.id.text_activeCasesIncriment);
|
||||
TextView textView10 = view.findViewById(R.id.text_recoveredDataIncriment);
|
||||
TextView textView11 = view.findViewById(R.id.text_deathsDataIncriment);
|
||||
String dailyIncWithCommas = numberFormat.format(cases[0] - ycases[0]);
|
||||
String dailyActWithCommas = numberFormat.format(ACases[0] - yACases[0]);
|
||||
String dailyDeathWithCommas = numberFormat.format(Toddeaths[0] - yDeaths[0]);
|
||||
String dailyRecoveredWithCommas = numberFormat.format(recovered[0] - yRecovered[0]);
|
||||
Log.d("foo", "I got here");
|
||||
|
||||
if ((cases[0] - ycases[0]) >= 0){
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "+" + dailyIncWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
else {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "-" + dailyIncWithCommas + "</i></b>"); SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
if((ACases[0] - yACases[0]) >= 0){
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "+" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "-" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
if((recovered[0] - yRecovered[0]) >= 0){
|
||||
textView10.setText(Html.fromHtml("<b><i>" + "+" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView10.setText(Html.fromHtml("<b><i>" + "-" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
}
|
||||
if((Toddeaths[0] - yDeaths[0]) >= 0){
|
||||
textView11.setText(Html.fromHtml("<b><i>" + "+" + dailyDeathWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView11.setText(Html.fromHtml("<b><i>" + "-" + dailyDeathWithCommas + "</i></b>"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//setData(vYourworldViewModel,world);
|
||||
|
||||
//final TextView textView5 = view.findViewById(R.id.text_activeCases);
|
||||
|
||||
//String totalCases = Integer.toString(yesworld.cases);
|
||||
|
||||
//textView5.setText(Html.fromHtml("<p><u>Yerterday cases</u></p>"+totalCases));
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
postRequest();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
private void postRequest() {
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourworldViewModel.postRequest(serviceRequest);
|
||||
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html){
|
||||
if(html == null){
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,24 @@
|
||||
package com.josh.trackcovid19v2.ui.yourworld;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class YourworldViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public YourworldViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("World Fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
|
||||
public void setText(String str) {
|
||||
mText.setValue(str);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user