Skip to content

Instantly share code, notes, and snippets.

View pratamawijaya's full-sized avatar

Pratama Nur Wijaya pratamawijaya

View GitHub Profile
public class MainActivity extends BaseActivity implements RecyclerItemClickListener.OnItemClickListener {
public static final int FROM_LOCAL = 0;
public static final int FROM_NET = 1;
@InjectView(R.id.recyclerview)
RecyclerView recyclerView;
@InjectView(R.id.emptytext)
TextView emptyText;
private void readDataFromDb() {
if (locationModels.size() > 0)
locationModels.clear();
RealmResults<LocationModel> result = realm
.where(LocationModel.class)
.findAll();
// sortiny by id.
// show greater first
result.sort("id", RealmResults.SORT_ORDER_DESCENDING);
for (LocationModel data : result) {
@Override
public void onItemClick(View v, int position) {
Toast.makeText(this, "" + locationModels.get(position).getTujuan(), Toast.LENGTH_SHORT).show();
Bundle data = new Bundle();
data.putInt("status", FROM_LOCAL);
data.putString("id", locationModels.get(position).getId());
startActivity(new Intent(this, ViewRouteActivity.class).putExtras(data));
}
data = getIntent().getExtras();
if (data.getInt("status") == MainActivity.FROM_LOCAL) {
// baca db
latLngList = readDataFromDB(data.getString("id"));
// draw
drawDirectionToMap(latLngList);
} else {
latAwal = data.getDouble("latAwal");
lngAwal = data.getDouble("lngAwal");
private List<LatLng> readDataFromDB(String id) {
RealmResults<LocationModel> result = realm.where(LocationModel.class).equalTo("id", id).findAll();
List<LatLng> listlatlng = new ArrayList<>();
for (LatLngModel data : result.get(0).getLatLngRealmList())
listlatlng.add(new LatLng(data.getLat(), data.getLng()));
return listlatlng;
}
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;
public class UtilsLog{
public static void DEBUG(String message){
if(BuildConfig.DEBUG){
Log.d("debug",message);
}
}
}
@pratamawijaya
pratamawijaya / activity_main.xml
Created May 29, 2015 16:49
navigation_drawer
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!-- content-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/primaryColor"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp">
<de.hdodenhof.circleimageview.CircleImageView
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home"
android:title="Home" />
<item
android:id="@+id/nav_contact"