Commit 840cfb84 authored by rahadi's avatar rahadi

WIP: refactored attrs for custom view, in progress to add footer view buttons listener

parent 785cb58a
......@@ -20,6 +20,7 @@ buildscript {
allprojects {
repositories {
// mavenCentral()
jcenter()
maven { url = 'https://oss.sonatype.org/content/groups/public' }
maven { url "https://maven.google.com" }
......
......@@ -208,14 +208,14 @@ dependencies {
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.6.0'
// tempat custom dependencies capi-stis, supaya gampang updatenya
// sudah ada ui-android, peta wb, revalidasi (soon)
compile('com.mikepenz:materialdrawer:6.0.2@aar') {
compile('com.mikepenz:materialdrawer:6.0.7@aar') {
transitive = true
}
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar') {
transitive = true
}
compile project(':slidingmenu')
compile project(':vsen_p')
// compile project(':vsen_p')
compile 'org.apache.commons:commons-lang3:3.6'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support:support-v4:26.1.0'
......@@ -231,4 +231,4 @@ dependencies {
// Must be at bottom to prevent dependency collisions
// https://developers.google.com/android/guides/google-services-plugin
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
apply plugin: 'com.google.gms.google-services'
This diff is collapsed.
......@@ -31,45 +31,34 @@ import com.mikepenz.materialdrawer.model.SectionDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
import com.rahadi.vsen.contexts.Vsen;
import com.rahadi.vsen.daos.BlokSensusDao;
import com.rahadi.vsen.daos.CatatanDao;
import com.rahadi.vsen.daos.DsrtDao;
import com.rahadi.vsen.daos.DsrtLogDao;
import com.rahadi.vsen.daos.RutaDao;
import com.rahadi.vsen.listeners.OnSynchronizationCompletedListener;
import com.rahadi.vsen.models.UserModel;
import com.rahadi.vsen.tasks.BSSynchronizationTask;
import com.squareup.picasso.Picasso;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import java.util.ArrayList;
import id.ac.stis.capi.R;
import id.ac.stis.capi.odk.activities.SplashScreenActivity;
import id.ac.stis.capi.collectiva.fragment.CapiFormFragment;
import id.ac.stis.capi.collectiva.preferences.CapiInstancePreferences;
import id.ac.stis.capi.odk.activities.SplashScreenActivity;
import id.ac.stis.capi.odk.database.ItemsetDbAdapter;
import id.ac.stis.capi.odk.listeners.DiskSyncListener;
import id.ac.stis.capi.pemutakhiran.fragments.BSFragment;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.tasks.DiskSyncTask;
import id.ac.stis.capi.petawbdigital.activities.GeoPointMapboxRevoActivity;
import id.ac.stis.capi.petawbdigital.assets.VAR;
import id.ac.stis.capi.petawbdigital.externals.AksesDataOdk;
import id.ac.stis.capi.petawbdigital.fragments.WbFragment;
import id.ac.stis.capi.petawbdigital.models.BlokSensus;
import id.ac.stis.capi.petawbdigital.models.Form;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.revalidasi.fragments.DataDownloadFragment;
import id.ac.stis.capi.revalidasi.notifikasi.GetUuidTask;
import id.ac.stis.capi.odk.tasks.DiskSyncTask;
import timber.log.Timber;
/**
* @author Muhammad Tohir
* edit Mahendri Dwicahyo
* edit Mahendri Dwicahyo
*/
public class CapiMainActivity extends AppCompatActivity implements DiskSyncListener {
......@@ -85,7 +74,6 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
private Drawer result;
private GeneralSharedPreferences prefs;
private CapiFormFragment capiListForms;
private BSFragment bsFragment;
private DataDownloadFragment dataDownloadFragment;
private WbFragment wbFragment;
private Toolbar toolbar;
......@@ -98,7 +86,6 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
toolbar = (Toolbar) findViewById(R.id.toolbar);
capiListForms = new CapiFormFragment();
bsFragment = BSFragment.newInstance();
dataDownloadFragment = DataDownloadFragment.newInstance();
wbFragment = WbFragment.newInstance();
prefs = GeneralSharedPreferences.getInstance();
......@@ -183,37 +170,38 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
pd.setMessage("Logging Out..");
pd.show();
UserModel um = Vsen.getInstance().getUserSession();
new BSSynchronizationTask(null, null).execute(um.getIdUser(), um.getAuthToken(),
new OnSynchronizationCompletedListener<JSONArray>() {
@Override
public void onSynchronizationCompleted(JSONArray result) {
pd.dismiss();
Vsen.getInstance().clearUserSession();
new BlokSensusDao().deleteBlokSensus();
new CatatanDao().deleteCatatan();
new DsrtDao().deleteDsrt();
new DsrtLogDao().deleteDsrtLog();
new RutaDao().deleteRuta();
prefs.reset(PreferenceKeys.KEY_LOGIN_STATUS);
prefs.reset(PreferenceKeys.KEY_USERNAME);
prefs.reset(PreferenceKeys.KEY_PASSWORD);
prefs.reset(PreferenceKeys.KEY_USERGROUP);
prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP);
String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES);
if (StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid));
startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class));
finish();
}
@Override
public void onSynchronizationFailed(Exception e) {
pd.dismiss();
Toast.makeText(CapiMainActivity.this, "Gagal Logout", Toast.LENGTH_LONG).show();
}
});
// UserModel um = Vsen.getInstance().getUserSession();
// new BSSynchronizationTask(null, null).execute(um.getIdUser(), um.getAuthToken(),
// new OnSynchronizationCompletedListener<JSONArray>() {
// @Override
// public void onSynchronizationCompleted(JSONArray result) {
// pd.dismiss();
// Vsen.getInstance().clearUserSession();
// new BlokSensusDao().deleteBlokSensus();
// new CatatanDao().deleteCatatan();
// new DsrtDao().deleteDsrt();
// new DsrtLogDao().deleteDsrtLog();
// new RutaDao().deleteRuta();
prefs.reset(PreferenceKeys.KEY_LOGIN_STATUS);
prefs.reset(PreferenceKeys.KEY_USERNAME);
prefs.reset(PreferenceKeys.KEY_PASSWORD);
prefs.reset(PreferenceKeys.KEY_USERGROUP);
prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP);
String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES);
if (StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid));
startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class));
finish();
// }
//
// @Override
// public void onSynchronizationFailed(Exception e) {
// pd.dismiss();
// Toast.makeText(CapiMainActivity.this, "Gagal Logout", Toast.LENGTH_LONG).show();
// }
// });
}
private void initializeDrawer(final Context context, Bundle savedInstanceState) {
......@@ -280,11 +268,11 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
switch ((int) drawerItem.getIdentifier()) {
case MENU_PEMUTAKHIRAN:
// startActivity(new Intent(context, BSActivity.class));
getSupportActionBar().setTitle("Pemutakhiran");
openFragment(bsFragment);
break;
// case MENU_PEMUTAKHIRAN:
//// startActivity(new Intent(context, BSActivity.class));
// getSupportActionBar().setTitle("Pemutakhiran");
// openFragment(bsFragment);
// break;
case MENUSURVEY:
getSupportActionBar().setTitle("Daftar Kuesioner");
......
......@@ -21,9 +21,6 @@ import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.rahadi.vsen.activities.VsenPreferenceActivity;
import com.rahadi.vsen.fragments.VsenPreferenceFragment;
import id.ac.stis.capi.R;
import id.ac.stis.capi.collectiva.ParseXml;
import id.ac.stis.capi.odk.dao.FormsDao;
......@@ -160,13 +157,13 @@ public class CapiInstancePreferences extends AppCompatActivity
startActivity(new Intent(this, KonfigurasiPeta.class));
finish();
break;
case R.id.updating_setting:
Intent i = new Intent(this, VsenPreferenceActivity.class);
i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, VsenPreferenceFragment.class.getName());
i.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
startActivity(i);
finish();
break;
// case R.id.updating_setting:
// Intent i = new Intent(this, VsenPreferenceActivity.class);
// i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, VsenPreferenceFragment.class.getName());
// i.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
// startActivity(i);
// finish();
// break;
}
}
......
package id.ac.stis.capi.lessthink.activities;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;
import java.util.LinkedHashMap;
import java.util.Map;
import id.ac.stis.capi.R;
import id.ac.stis.capi.lessthink.views.TableFooterView;
import id.ac.stis.capi.lessthink.views.TableHeaderView;
import id.ac.stis.capi.lessthink.views.TableRowView;
public class ListingInstanceActivity extends AppCompatActivity {
private TableHeaderView tableHeaderView;
private TableRowView tableRowView;
private TableFooterView tableFooterView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listing_instance);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
tableHeaderView = findViewById(R.id.header_view);
tableRowView = findViewById(R.id.row_view);
tableFooterView = findViewById(R.id.footer_view);
Map<String, String> headerList = new LinkedHashMap<>();
headerList.put("no_sls", "No. SLS");
headerList.put("no_bs", "No. BS");
headerList.put("no_bf", "No. BF");
headerList.put("no_nks", "No. NKS");
headerList.put("nama_krt", "Nama KRT");
tableHeaderView.setColumns(headerList);
Map<String, Map<String, String>> rowData = new LinkedHashMap<>();
for (int i = 0; i < 15; i++) {
Map<String, String> row = new LinkedHashMap<>();
row.put("no_sls", (i < 9 ? "00" : "0") + (i + 1));
row.put("no_bs", (i < 9 ? "00" : "0") + (i + 1));
row.put("no_bf", (i < 9 ? "00" : "0") + (i + 1));
row.put("no_nks", (i < 9 ? "00" : "0") + (i + 1));
row.put("nama_krt", "Nama KRT " + i);
rowData.put("rowwithid" + i, row);
}
tableRowView.setRows(rowData);
tableRowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(ListingInstanceActivity.this, "Click : " + view.getTag(), Toast.LENGTH_LONG).show();
}
});
}
}
package id.ac.stis.capi.lessthink.listeners;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface OnHandlerMovedListener {
void onStartMoving(String key);
void onMoving(String key);
void onStopMoving(String key);
}
package id.ac.stis.capi.lessthink.listeners;
import android.view.View;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface OnRecyclerItemClickListener {
void onItemClick(View v, int position);
}
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import id.ac.stis.capi.R;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class ListingTableView extends View {
public static final int COLUMN_TYPE_HEADER = 1;
public static final int COLUMN_TYPE_BODY = 2;
public static final int SEP_TYPE_HEADER = 3;
public static final int SEP_TYPE_BODY = 4;
private static final int KEY_COLUMN_IDX = 0;
/*
The HashMap<String, String> should be in the form of:
key: header key
value: header name value
*/
private HashMap<String, String> headerList;
/*
ArrayList<> denotes as rows.
The HashMap<String, String> should be in the form of:
key: header key
value: row value
*/
private ArrayList<HashMap<String, String>> rowData;
private LinearLayout headerContainer, rowContainer;
public ListingTableView(Context context) {
super(context);
}
public ListingTableView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public ListingTableView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void init(HashMap<String, String> headerList, ArrayList<HashMap<String, String>> rowData) {
this.headerList = headerList;
this.rowData = rowData;
init();
}
private void init() {
// TODO: 06/06/2018 Proper exception
// if (headerList.size() != rowData.size()) {
// throw new DimensionInvalidException("Number of Column is Invalid");
// }
View v = LayoutInflater.from(getContext()).inflate(R.layout.view_listing_table,
null, false);
headerContainer = v.findViewById(R.id.header_container);
rowContainer = v.findViewById(R.id.row_container);
// Creates Header
int headerIdx = 0;
Set<String> headerKeySet = headerList.keySet();
for (String headerKey : headerKeySet) {
TextView header = createNewColumn(COLUMN_TYPE_HEADER, headerKey,
headerList.get(headerKey), headerIdx);
headerContainer.addView(header);
View separator = createNewSeparator(SEP_TYPE_HEADER, headerKey, headerIdx);
headerContainer.addView(separator);
headerIdx++;
}
// Creates Row
for (int i = 0; i < rowData.size(); i++) {
LinearLayout row = createNewRow(rowData.get(i), i);
rowContainer.addView(row);
}
}
private TextView createNewColumn(int type, String key, String value, int columnIdx) {
TextView column = new TextView(getContext());
column.setTag(key);
column.setTag(KEY_COLUMN_IDX, columnIdx);
column.setText(value);
switch (type) {
case COLUMN_TYPE_HEADER:
column.setContentDescription("h-" + columnIdx);
return column;
case COLUMN_TYPE_BODY:
column.setContentDescription("b-" + columnIdx);
column.setTag(key);
return column;
}
return null;
}
private View createNewSeparator(int type, String key, int columnIdx) {
View separator = new View(getContext());
separator.setTag(key);
separator.setTag(KEY_COLUMN_IDX, columnIdx);
switch (type) {
case SEP_TYPE_HEADER:
separator.setContentDescription("sh-" + columnIdx);
final TextView column = headerContainer.findViewWithTag(key);
column.measure(0, 0);
final int oriWidth = column.getMeasuredWidth();
final ArrayList<View> rowInBodyList = new ArrayList<>();
headerContainer.findViewsWithText(rowInBodyList, "b-" + columnIdx,
FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
separator.setOnTouchListener(new View.OnTouchListener() {
int prevX;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
prevX = (int) motionEvent.getRawX();
return true;
case MotionEvent.ACTION_MOVE:
if (column.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX >= oriWidth) {
column.setWidth(column.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
for (View rowInBody : rowInBodyList) {
((TextView) rowInBody).setWidth(rowInBody.getMeasuredWidth()
+ (int) motionEvent.getRawX() - prevX);
}
prevX = (int) motionEvent.getRawX();
}
return true;
}
return false;
}
});
return separator;
case SEP_TYPE_BODY:
separator.setContentDescription("sb-" + columnIdx);
return separator;
}
return null;
}
private LinearLayout createNewRow(HashMap<String, String> data, int rowIdx) {
LinearLayout row = new LinearLayout(getContext());
row.setContentDescription("r-" + rowIdx);
row.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
row.setLayoutParams(params);
Set<String> dataKeySet = data.keySet();
for (String dataKey : dataKeySet) {
int idxPosition = (Integer) headerContainer.findViewWithTag(dataKey).getTag(KEY_COLUMN_IDX);
TextView column = createNewColumn(COLUMN_TYPE_BODY, dataKey, data.get(dataKey), idxPosition);
row.addView(column);
View separator = createNewSeparator(SEP_TYPE_BODY, dataKey, idxPosition);
headerContainer.addView(separator);
}
return row;
}
// final HorizontalScrollView header = findViewById(R.id.header_layout);
// header.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
// return true;
// }
// });
//
// final TextView column1 = findViewById(R.id.column_1);
// column1.measure(0, 0);
//
// final TextView row1 = findViewById(R.id.row_1);
//
// final View dragme = findViewById(R.id.dragme);
// final int oriWidth = column1.getMeasuredWidth();
// dragme.setOnTouchListener(new View.OnTouchListener() {
//
// int prevX;
//
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
// view.getParent().requestDisallowInterceptTouchEvent(true);
// switch (motionEvent.getAction()) {
// case MotionEvent.ACTION_DOWN:
// prevX = (int) motionEvent.getRawX();
// return true;
// case MotionEvent.ACTION_MOVE:
// if(column1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX >= oriWidth) {
// column1.setWidth(column1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
// row1.setWidth(row1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
// prevX = (int) motionEvent.getRawX();
// }
// return true;
// }
// return false;
// }
// });
//
// final HorizontalScrollView scrollView = findViewById(R.id.scroll_view);
//
// scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
// @Override
// public void onScrollChanged() {
// header.scrollTo(scrollView.getScrollX(), 0);
// }
// });
}
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class ObservableHorizontalScrollView extends HorizontalScrollView {
public interface OnScrollListener {
public void onScrollChanged(ObservableHorizontalScrollView scrollView, int x, int y, int oldX, int oldY);
public void onEndScroll(ObservableHorizontalScrollView scrollView);
}
private boolean mIsScrolling;
private boolean mIsTouching;
private Runnable mScrollingRunnable;
private OnScrollListener mOnScrollListener;
public ObservableHorizontalScrollView(Context context) {
this(context, null, 0);
}
public ObservableHorizontalScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ObservableHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
if (action == MotionEvent.ACTION_MOVE) {
mIsTouching = true;
mIsScrolling = true;
} else if (action == MotionEvent.ACTION_UP) {
if (mIsTouching && !mIsScrolling) {
if (mOnScrollListener != null) {
mOnScrollListener.onEndScroll(this);
}
}
mIsTouching = false;
}
return super.onTouchEvent(ev);
}
@Override
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
super.onScrollChanged(x, y, oldX, oldY);
if (Math.abs(oldX - x) > 0) {
if (mScrollingRunnable != null) {
removeCallbacks(mScrollingRunnable);
}
mScrollingRunnable = new Runnable() {
public void run() {
if (mIsScrolling && !mIsTouching) {
if (mOnScrollListener != null) {
mOnScrollListener.onEndScroll(ObservableHorizontalScrollView.this);
}
}
mIsScrolling = false;
mScrollingRunnable = null;
}
};
postDelayed(mScrollingRunnable, 200);
}
if (mOnScrollListener != null) {
mOnScrollListener.onScrollChanged(this, x, y, oldX, oldY);
}
}
public OnScrollListener getOnScrollListener() {
return mOnScrollListener;
}
public void setOnScrollListener(OnScrollListener mOnEndScrollListener) {
this.mOnScrollListener = mOnEndScrollListener;
}
}
\ No newline at end of file
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.content.res.TypedArray;