mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Integrated Swipe Layout
This commit is contained in:
@@ -5,6 +5,7 @@ import androidx.appcompat.app.ActionBar;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -51,6 +52,8 @@ public class FoodList extends AppCompatActivity {
|
|||||||
//Favorites
|
//Favorites
|
||||||
Database localDB;
|
Database localDB;
|
||||||
|
|
||||||
|
SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -63,24 +66,53 @@ public class FoodList extends AppCompatActivity {
|
|||||||
//Local DB
|
//Local DB
|
||||||
localDB = new Database(this);
|
localDB = new Database(this);
|
||||||
|
|
||||||
|
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
|
||||||
|
swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary,
|
||||||
|
android.R.color.holo_green_dark,
|
||||||
|
android.R.color.holo_orange_dark,
|
||||||
|
android.R.color.holo_blue_dark);
|
||||||
|
|
||||||
|
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
//Get Intent here
|
||||||
|
if(getIntent() != null)
|
||||||
|
categoryId = getIntent().getStringExtra("CategoryId");
|
||||||
|
categoryName = getIntent().getStringExtra("CategoryName");
|
||||||
|
if(!categoryId.isEmpty() && categoryId != null) {
|
||||||
|
if(Common.isConnectedToInternet(getBaseContext()))
|
||||||
|
loadListFood(categoryId);
|
||||||
|
else {
|
||||||
|
Toast.makeText(FoodList.this, "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
swipeRefreshLayout.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//Get Intent here
|
||||||
|
if(getIntent() != null)
|
||||||
|
categoryId = getIntent().getStringExtra("CategoryId");
|
||||||
|
categoryName = getIntent().getStringExtra("CategoryName");
|
||||||
|
if(!categoryId.isEmpty() && categoryId != null) {
|
||||||
|
if(Common.isConnectedToInternet(getBaseContext()))
|
||||||
|
loadListFood(categoryId);
|
||||||
|
else {
|
||||||
|
Toast.makeText(FoodList.this, "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
recyclerView = (RecyclerView) findViewById(R.id.recyler_food);
|
recyclerView = (RecyclerView) findViewById(R.id.recyler_food);
|
||||||
recyclerView.setHasFixedSize(true);
|
recyclerView.setHasFixedSize(true);
|
||||||
layoutManager = new LinearLayoutManager(this);
|
layoutManager = new LinearLayoutManager(this);
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
//Get Intent here
|
|
||||||
if(getIntent() != null)
|
|
||||||
categoryId = getIntent().getStringExtra("CategoryId");
|
|
||||||
categoryName = getIntent().getStringExtra("CategoryName");
|
|
||||||
if(!categoryId.isEmpty() && categoryId != null) {
|
|
||||||
if(Common.isConnectedToInternet(getBaseContext()))
|
|
||||||
loadListFood(categoryId);
|
|
||||||
else {
|
|
||||||
Toast.makeText(FoodList.this, "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Search
|
//Search
|
||||||
materialSearchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
|
materialSearchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
|
||||||
materialSearchBar.setHint("Enter your food");
|
materialSearchBar.setHint("Enter your food");
|
||||||
@@ -228,6 +260,7 @@ public class FoodList extends AppCompatActivity {
|
|||||||
|
|
||||||
//Set Adapter
|
//Set Adapter
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import androidx.drawerlayout.widget.DrawerLayout;
|
|||||||
import androidx.navigation.ui.AppBarConfiguration;
|
import androidx.navigation.ui.AppBarConfiguration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||||
import com.google.android.gms.tasks.OnCompleteListener;
|
import com.google.android.gms.tasks.OnCompleteListener;
|
||||||
@@ -53,7 +54,7 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
RecyclerView.LayoutManager layoutManager;
|
RecyclerView.LayoutManager layoutManager;
|
||||||
FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter;
|
FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter;
|
||||||
|
|
||||||
private AppBarConfiguration mAppBarConfiguration;
|
SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -65,6 +66,37 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
toolbar.setTitle("Menu");
|
toolbar.setTitle("Menu");
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
//View
|
||||||
|
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
|
||||||
|
swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary,
|
||||||
|
android.R.color.holo_green_dark,
|
||||||
|
android.R.color.holo_orange_dark,
|
||||||
|
android.R.color.holo_blue_dark);
|
||||||
|
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
if (Common.isConnectedToInternet(getBaseContext()))
|
||||||
|
loadMenu();
|
||||||
|
else {
|
||||||
|
Toast.makeText(getBaseContext(), "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Default, load for first time
|
||||||
|
swipeRefreshLayout.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (Common.isConnectedToInternet(getBaseContext()))
|
||||||
|
loadMenu();
|
||||||
|
else {
|
||||||
|
Toast.makeText(getBaseContext(), "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.app_name, R.string.app_name);
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.app_name, R.string.app_name);
|
||||||
drawer.setDrawerListener(toggle);
|
drawer.setDrawerListener(toggle);
|
||||||
@@ -86,14 +118,6 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
layoutManager = new LinearLayoutManager(this);
|
layoutManager = new LinearLayoutManager(this);
|
||||||
recyler_menu.setLayoutManager(layoutManager);
|
recyler_menu.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
if (Common.isConnectedToInternet(getBaseContext()))
|
|
||||||
loadMenu();
|
|
||||||
else {
|
|
||||||
Toast.makeText(this, "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Set name for user
|
//Set name for user
|
||||||
View headerView = navigationView.getHeaderView(0);
|
View headerView = navigationView.getHeaderView(0);
|
||||||
TextView navUserName = (TextView) headerView.findViewById(R.id.txtFullName);
|
TextView navUserName = (TextView) headerView.findViewById(R.id.txtFullName);
|
||||||
@@ -131,7 +155,7 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
recyler_menu.setAdapter(adapter);
|
recyler_menu.setAdapter(adapter);
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,26 +1,33 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/swipe_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".FoodList">
|
tools:context=".FoodList">
|
||||||
|
|
||||||
<com.mancj.materialsearchbar.MaterialSearchBar
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent">
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:id="@+id/searchBar"
|
|
||||||
app:mt_speechMode="false"
|
|
||||||
app:mt_hint="Enter your food"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<com.mancj.materialsearchbar.MaterialSearchBar
|
||||||
android:layout_below="@+id/searchBar"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_alignParentTop="true"
|
||||||
android:id="@+id/recyler_food"
|
android:id="@+id/searchBar"
|
||||||
android:scrollbars="vertical"
|
app:mt_speechMode="false"
|
||||||
/>
|
app:mt_hint="Enter your food"
|
||||||
|
/>
|
||||||
|
|
||||||
</RelativeLayout>
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:layout_below="@+id/searchBar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/recyler_food"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/swipe_layout"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -14,4 +15,4 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:scrollbars="vertical" />
|
android:scrollbars="vertical" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
Reference in New Issue
Block a user