Created
September 16, 2020 05:48
-
-
Save axarlotwala/bd987cf9a39303b0bd3ea1406e477ef7 to your computer and use it in GitHub Desktop.
asymmetriclayout in Android or Complex Listview In Android or Endless View Dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout 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:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_marginBottom="@dimen/_50sdp" | |
tools:context=".HomeScreen.fragment.HomeFragment"> | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<RelativeLayout | |
android:id="@+id/topItem" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_marginTop="@dimen/_5sdp"> | |
<EditText | |
android:id="@+id/etSearch" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:background="@drawable/plain_rectangle" | |
android:drawableRight="@drawable/ic_search_black_24dp" | |
android:paddingLeft="@dimen/_5sdp" | |
android:paddingTop="@dimen/_5sdp" | |
android:paddingBottom="@dimen/_5sdp" | |
android:layout_marginLeft="@dimen/_10ssp" | |
android:layout_marginRight="@dimen/_10sdp"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/complexView" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_below="@id/etSearch" | |
android:layout_marginTop="@dimen/_10sdp" | |
android:visibility="gone"/> | |
<LinearLayout | |
android:id="@+id/complexLinearLayout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_below="@id/etSearch" | |
android:orientation="vertical"/> | |
</RelativeLayout> | |
</RelativeLayout> | |
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.GroceryStore.com.HomeScreen.fragment; | |
import android.annotation.SuppressLint; | |
import android.content.res.Resources; | |
import android.graphics.Color; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.util.DisplayMetrics; | |
import android.util.Log; | |
import android.util.TypedValue; | |
import android.view.Gravity; | |
import android.view.LayoutInflater; | |
import android.view.Menu; | |
import android.view.MenuInflater; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.CheckBox; | |
import android.widget.EditText; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import android.widget.RadioButton; | |
import android.widget.RadioGroup; | |
import android.widget.RelativeLayout; | |
import android.widget.ScrollView; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
import androidx.core.content.ContextCompat; | |
import androidx.core.widget.NestedScrollView; | |
import androidx.fragment.app.Fragment; | |
import androidx.recyclerview.widget.DividerItemDecoration; | |
import androidx.recyclerview.widget.GridLayoutManager; | |
import androidx.recyclerview.widget.LinearLayoutManager; | |
import androidx.recyclerview.widget.RecyclerView; | |
import androidx.viewpager.widget.ViewPager; | |
import com.GroceryStore.com.HomeScreen.adapter.HomeComplexAdapter; | |
import com.GroceryStore.com.HomeScreen.adapter.OurServicesAdapter; | |
import com.GroceryStore.com.HomeScreen.model.OurServicesModel; | |
import com.GroceryStore.com.R; | |
import com.GroceryStore.com.adapter.CategoryAdapter; | |
import com.GroceryStore.com.adapter.ProductAdapter; | |
import com.GroceryStore.com.adapter.SliderAdapter; | |
import com.GroceryStore.com.model.CategoryModel; | |
import com.GroceryStore.com.model.ProductModel; | |
import com.GroceryStore.com.model.SliderModel; | |
import com.GroceryStore.com.utils.OpenHelper; | |
import com.GroceryStore.com.utils.ProgressbarUtils; | |
import com.GroceryStore.com.utils.SpaceItemDecoration; | |
import com.google.android.gms.tasks.OnCompleteListener; | |
import com.google.android.gms.tasks.Task; | |
import com.google.firebase.firestore.DocumentSnapshot; | |
import com.google.firebase.firestore.FirebaseFirestore; | |
import com.google.firebase.firestore.QuerySnapshot; | |
import java.util.ArrayList; | |
import java.util.List; | |
import me.relex.circleindicator.CircleIndicator; | |
public class HomeFragment extends Fragment { | |
RecyclerView complexView; | |
public FirebaseFirestore firebaseFirestore; | |
EditText etSearch; | |
private LinearLayout complexLinearLayout; | |
private List<SliderModel> sliderModels; | |
RecyclerView vegetableListView, ourServicesListView, categoryListView, popularProductListView, fruitsListView; | |
private int dotsCount; | |
ProgressbarUtils progressbarUtils; | |
private List<Object> objects; | |
public HomeFragment() { | |
} | |
@Nullable | |
@Override | |
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_home, container, false); | |
return view; | |
} | |
@SuppressLint("NewApi") | |
@Override | |
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
complexView = view.findViewById(R.id.complexView); | |
firebaseFirestore = FirebaseFirestore.getInstance(); | |
etSearch = view.findViewById(R.id.etSearch); | |
complexLinearLayout = view.findViewById(R.id.complexLinearLayout); | |
setHasOptionsMenu(true); | |
progressbarUtils = new ProgressbarUtils(getActivity()); | |
try { | |
progressbarUtils.show(); | |
NestedScrollView scrollView = new NestedScrollView(getActivity()); | |
LinearLayout.LayoutParams scrollParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | |
scrollView.setLayoutParams(scrollParams); | |
LinearLayout mainLinearLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams mainParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | |
mainLinearLayout.setOrientation(LinearLayout.VERTICAL); | |
mainLinearLayout.setLayoutParams(mainParams); | |
scrollView.addView(mainLinearLayout); | |
/* | |
* First Slider View | |
* */ | |
try { | |
LinearLayout topSliderLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,520); | |
// topSliderLayout.setOrientation(LinearLayout.VERTICAL); | |
topSliderLayout.setLayoutParams(layoutParams); | |
layoutParams.setMargins(15, 15, 15, 15); | |
// getSlider(); | |
SliderAdapter sliderAdapter = new SliderAdapter(getActivity(), getSlider()); | |
ViewPager pager = new ViewPager(getActivity()); | |
pager.setAdapter(sliderAdapter); | |
pager.setLayoutParams(layoutParams); | |
topSliderLayout.addView(pager); | |
mainLinearLayout.addView(topSliderLayout); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.e("TopSliderLayoutError", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* Popular Product With ViewMore | |
* */ | |
try { | |
LinearLayout mainPopularProduct = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams popularLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | |
mainPopularProduct.setOrientation(LinearLayout.VERTICAL); | |
mainPopularProduct.setLayoutParams(popularLayoutParams); | |
LinearLayout popularLinearLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams popularHorizontalParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
popularLinearLayout.setOrientation(LinearLayout.HORIZONTAL); | |
popularLinearLayout.setLayoutParams(popularHorizontalParams); | |
//layoutParams.setMargins(10,10,10,10); | |
TextView textViewPop = new TextView(getActivity()); | |
LinearLayout.LayoutParams textParamsPopular = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textViewPop.setLayoutParams(textParamsPopular); | |
textViewPop.setText("Popular Item"); | |
textViewPop.setPadding(10, 15, 10, 10); | |
textParamsPopular.setMargins(10, 15, 10, 10); | |
popularLinearLayout.addView(textViewPop); | |
TextView textViewPopMore = new TextView(getActivity()); | |
LinearLayout.LayoutParams textParamsPopMore = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textViewPopMore.setLayoutParams(textParamsPopMore); | |
textParamsPopMore.setMargins(10, 15, 10, 10); | |
textViewPopMore.setPadding(10, 15, 10, 10); | |
popularLinearLayout.addView(textViewPopMore); | |
textViewPopMore.setGravity(Gravity.RIGHT); | |
textViewPopMore.setText("View More"); | |
popularProductListView = new RecyclerView(getActivity()); | |
LinearLayout.LayoutParams attachParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
GridLayoutManager popularItemGrid = new GridLayoutManager(getActivity(), 2); | |
popularProductListView.setLayoutManager(popularItemGrid); | |
popularProductListView.setLayoutParams(attachParams); | |
mainPopularProduct.addView(popularLinearLayout); | |
mainPopularProduct.addView(popularProductListView); | |
setPopularProduct(); | |
mainLinearLayout.addView(mainPopularProduct); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.e("popularProduct", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* set our Top Categories with text | |
* */ | |
try { | |
LinearLayout ourCategoryLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams categoryLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
ourCategoryLayout.setOrientation(LinearLayout.VERTICAL); | |
ourCategoryLayout.setLayoutParams(categoryLayoutParams); | |
categoryLayoutParams.setMargins(10, 10, 10, 10); | |
TextView ourCategoryView = new TextView(getActivity()); | |
LinearLayout.LayoutParams textCategoryParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
ourCategoryView.setLayoutParams(textCategoryParams); | |
ourCategoryView.setText("Top Category"); | |
textCategoryParams.setMargins(10, 10, 10, 10); | |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); | |
categoryListView = new RecyclerView(getActivity()); | |
categoryListView.setLayoutParams(params); | |
categoryListView.setLayoutManager(linearLayoutManager); | |
CategoryAdapter categoryAdapter = new CategoryAdapter(getActivity(), categoryModelList()); | |
categoryListView.setAdapter(categoryAdapter); | |
ourCategoryLayout.addView(ourCategoryView); | |
ourCategoryLayout.addView(categoryListView); | |
mainLinearLayout.addView(ourCategoryLayout); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.e("topCategory", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* Vegetables List View With View More | |
* */ | |
try { | |
LinearLayout mainVegetableLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams mainVegLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
mainVegetableLayout.setOrientation(LinearLayout.VERTICAL); | |
mainVegetableLayout.setLayoutParams(mainVegLayoutParams); | |
LinearLayout linearLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams horizontalParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
linearLayout.setOrientation(LinearLayout.HORIZONTAL); | |
linearLayout.setLayoutParams(horizontalParams); | |
//layoutParams.setMargins(10,10,10,10); | |
TextView textView1 = new TextView(getActivity()); | |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textView1.setLayoutParams(textParams); | |
textView1.setText("Top Vegetables"); | |
textView1.setPadding(10, 15, 10, 10); | |
textParams.setMargins(10, 15, 10, 10); | |
linearLayout.addView(textView1); | |
TextView textView2 = new TextView(getActivity()); | |
LinearLayout.LayoutParams textParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textView2.setLayoutParams(textParams2); | |
textParams2.setMargins(10, 15, 10, 10); | |
textView2.setPadding(10, 15, 10, 10); | |
linearLayout.addView(textView2); | |
textView2.setGravity(Gravity.RIGHT); | |
textView2.setText("View More"); | |
vegetableListView = new RecyclerView(getActivity()); | |
LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2); | |
vegetableListView.setLayoutManager(gridLayoutManager); | |
vegetableListView.setLayoutParams(layoutParams1); | |
mainVegetableLayout.addView(linearLayout); | |
mainVegetableLayout.addView(vegetableListView); | |
setVegeTables(); | |
mainLinearLayout.addView(mainVegetableLayout); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.e("vegetablesView", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* Provide our Services View | |
* */ | |
try { | |
LinearLayout ourServicesLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams ourServicesParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
ourServicesLayout.setOrientation(LinearLayout.VERTICAL); | |
ourServicesLayout.setLayoutParams(ourServicesParams); | |
ourServicesParams.setMargins(15, 15, 15, 15); | |
LinearLayout textLinearLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams textLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textLinearLayout.setOrientation(LinearLayout.VERTICAL); | |
textLinearLayout.setLayoutParams(textLayoutParams); | |
TextView textViewOurServices = new TextView(getActivity()); | |
LinearLayout.LayoutParams servicesParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textViewOurServices.setLayoutParams(servicesParams); | |
textViewOurServices.setText("Our Services"); | |
textViewOurServices.setPadding(10, 15, 10, 10); | |
servicesParams.setMargins(10, 15, 10, 10); | |
textLinearLayout.addView(textViewOurServices); | |
ourServicesListView = new RecyclerView(getActivity()); | |
LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
GridLayoutManager gridLayoutManager1 = new GridLayoutManager(getActivity(), 2); | |
ourServicesListView.setLayoutManager(gridLayoutManager1); | |
ourServicesListView.setLayoutParams(layoutParams2); | |
ourServices(); | |
OurServicesAdapter ourServicesAdapter = new OurServicesAdapter(getActivity(), ourServices()); | |
ourServicesListView.setAdapter(ourServicesAdapter); | |
ourServicesLayout.addView(textLinearLayout); | |
ourServicesLayout.addView(ourServicesListView); | |
mainLinearLayout.addView(ourServicesLayout); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.e("ourServices", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* special offer slider | |
* */ | |
try { | |
LinearLayout mainSpecialOffer = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams mainSpecialOfferLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
mainSpecialOffer.setOrientation(LinearLayout.VERTICAL); | |
mainSpecialOffer.setLayoutParams(mainSpecialOfferLayoutParams); | |
LinearLayout specialOfferLiner = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams specialOfferLinearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
specialOfferLiner.setOrientation(LinearLayout.HORIZONTAL); | |
specialOfferLiner.setLayoutParams(specialOfferLinearParams); | |
//layoutParams.setMargins(10,10,10,10); | |
TextView textViewSpecialOffer = new TextView(getActivity()); | |
LinearLayout.LayoutParams textParamsOffer = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
textViewSpecialOffer.setLayoutParams(textParamsOffer); | |
textViewSpecialOffer.setText("Special Offers"); | |
textViewSpecialOffer.setPadding(10, 15, 10, 10); | |
textParamsOffer.setMargins(10, 15, 10, 10); | |
specialOfferLiner.addView(textViewSpecialOffer); | |
LinearLayout topSpecialOfferLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams specialOfferLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 520); | |
topSpecialOfferLayout.setOrientation(LinearLayout.VERTICAL); | |
topSpecialOfferLayout.setLayoutParams(specialOfferLayoutParams); | |
specialOfferLayoutParams.setMargins(15, 15, 15, 15); | |
SliderAdapter specialOfferSlider = new SliderAdapter(getActivity(), specialOfferSlider()); | |
ViewPager specialOfferPager = new ViewPager(getActivity()); | |
specialOfferPager.setAdapter(specialOfferSlider); | |
specialOfferPager.setLayoutParams(specialOfferLayoutParams); | |
topSpecialOfferLayout.addView(specialOfferPager); | |
mainSpecialOffer.addView(specialOfferLiner); | |
mainSpecialOffer.addView(topSpecialOfferLayout); | |
mainLinearLayout.addView(mainSpecialOffer); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.e("specialOfferSlider", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* Top Fruits | |
* */ | |
try { | |
LinearLayout mainFruitsLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams mainFruitsLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
mainFruitsLayout.setOrientation(LinearLayout.VERTICAL); | |
mainFruitsLayout.setLayoutParams(mainFruitsLayoutParams); | |
LinearLayout fruitLinearLayout = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams horizontalFruitParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
fruitLinearLayout.setOrientation(LinearLayout.HORIZONTAL); | |
fruitLinearLayout.setLayoutParams(horizontalFruitParams); | |
//layoutParams.setMargins(10,10,10,10); | |
TextView textViewFruitItem = new TextView(getActivity()); | |
LinearLayout.LayoutParams textFruitsParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textViewFruitItem.setLayoutParams(textFruitsParams); | |
textViewFruitItem.setText("Top Fruits"); | |
textViewFruitItem.setPadding(10, 15, 10, 10); | |
textFruitsParams.setMargins(10, 15, 10, 10); | |
fruitLinearLayout.addView(textViewFruitItem); | |
TextView textViewMoreFruit = new TextView(getActivity()); | |
LinearLayout.LayoutParams textFruitMoreParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
textViewMoreFruit.setLayoutParams(textFruitMoreParams); | |
textFruitMoreParams.setMargins(10, 15, 10, 10); | |
textViewMoreFruit.setPadding(10, 15, 10, 10); | |
fruitLinearLayout.addView(textViewMoreFruit); | |
textViewMoreFruit.setGravity(Gravity.RIGHT); | |
textViewMoreFruit.setText("View More"); | |
fruitsListView = new RecyclerView(getActivity()); | |
LinearLayout.LayoutParams fruitsListViewParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
GridLayoutManager fruitsLayoutManager = new GridLayoutManager(getActivity(), 2); | |
fruitsListView.setLayoutManager(fruitsLayoutManager); | |
fruitsListView.setLayoutParams(fruitsListViewParams); | |
mainFruitsLayout.addView(fruitLinearLayout); | |
mainFruitsLayout.addView(fruitsListView); | |
setFruitsItem(); | |
mainLinearLayout.addView(mainFruitsLayout); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.e("topFruits", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* Cashback Offer | |
* */ | |
try { | |
LinearLayout mainCashBackOffer = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams mainCashBackOfferLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
mainCashBackOffer.setOrientation(LinearLayout.VERTICAL); | |
mainCashBackOffer.setLayoutParams(mainCashBackOfferLayoutParams); | |
LinearLayout cashBackOfferLiner = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams cashBackOfferLinearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
cashBackOfferLiner.setOrientation(LinearLayout.HORIZONTAL); | |
cashBackOfferLiner.setLayoutParams(cashBackOfferLinearParams); | |
//layoutParams.setMargins(10,10,10,10); | |
TextView textViewCashBackOffer = new TextView(getActivity()); | |
LinearLayout.LayoutParams textViewCashBackOfferParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
textViewCashBackOffer.setLayoutParams(textViewCashBackOfferParams); | |
textViewCashBackOffer.setText("CashBack Offers"); | |
textViewCashBackOffer.setPadding(10, 15, 10, 10); | |
textViewCashBackOfferParams.setMargins(10, 15, 10, 10); | |
cashBackOfferLiner.addView(textViewCashBackOffer); | |
LinearLayout linearCashBackOffer = new LinearLayout(getActivity()); | |
LinearLayout.LayoutParams linearCashBackOfferParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,520); | |
//linearCashBackOffer.setOrientation(LinearLayout.VERTICAL); | |
linearCashBackOffer.setLayoutParams(linearCashBackOfferParams); | |
linearCashBackOfferParams.setMargins(10, 10, 10, 10); | |
SliderAdapter specialCashBackOfferSlider = new SliderAdapter(getActivity(), cashBackOffer()); | |
ViewPager cashBackOfferPager = new ViewPager(getActivity()); | |
cashBackOfferPager.setAdapter(specialCashBackOfferSlider); | |
cashBackOfferPager.setLayoutParams(linearCashBackOfferParams); | |
linearCashBackOffer.addView(cashBackOfferPager); | |
mainCashBackOffer.addView(cashBackOfferLiner); | |
mainCashBackOffer.addView(linearCashBackOffer); | |
mainLinearLayout.addView(mainCashBackOffer); | |
} catch (Exception e){ | |
Log.d("cashbackOffer", "onViewCreated: "+e.toString()); | |
} | |
/* | |
* add CheckList View | |
* */ | |
complexLinearLayout.addView(scrollView); | |
progressbarUtils.hide(); | |
} catch (Exception e) { | |
Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_SHORT).show(); | |
Log.e("ErrorGet", "onViewCreated: " + e.toString()); | |
} | |
} | |
private List<SliderModel> getSlider() { | |
List<SliderModel> sliderModels = new ArrayList<>(); | |
sliderModels.add(new SliderModel("https://moneyexcel.com/images/special_offers.png")); | |
sliderModels.add(new SliderModel("https://static.toiimg.com/photo/msid-71360475/71360475.jpg")); | |
sliderModels.add(new SliderModel("https://cascade.madmimi.com/promotion_images/9403/5965/original/PMS2019JUN_FLASH_SALE_eDM.jpg?1557825073")); | |
sliderModels.add(new SliderModel("https://promocodeclub.com/wp-content/uploads/2019/05/Amazon-swiggy.png")); | |
sliderModels.add(new SliderModel("https://static.hub.91mobiles.com/wp-content/uploads/2019/09/Amazon-great-indian-festival-sale.jpg")); | |
return sliderModels; | |
} | |
private List<CategoryModel> categoryModelList() { | |
final List<CategoryModel> categoryModels = new ArrayList<>(); | |
categoryModels.add(new CategoryModel("1", R.drawable.ic_vegetable, "Vegetables")); | |
categoryModels.add(new CategoryModel("2", R.drawable.ic_fruits, "Fruits")); | |
categoryModels.add(new CategoryModel("3", R.drawable.ic_meat, "Meat")); | |
categoryModels.add(new CategoryModel("4", R.drawable.ic_fish, "SeeFood")); | |
categoryModels.add(new CategoryModel("5", R.drawable.ic_milk, "Milk")); | |
categoryModels.add(new CategoryModel("6", R.drawable.ic_bread, "Bread")); | |
categoryModels.add(new CategoryModel("7", R.drawable.ic_frozen_yogurt, "Frozen")); | |
categoryModels.add(new CategoryModel("8", R.drawable.ic_seed_bag, "Organic")); | |
categoryModels.add(new CategoryModel("8", R.drawable.ic_egg, "Egg")); | |
return categoryModels; | |
} | |
private void setVegeTables() { | |
final List<ProductModel> vegetablesModel = new ArrayList<>(); | |
firebaseFirestore.collection(OpenHelper.PRODUCT).whereEqualTo("productCategory", "Vegetables").limit(4).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { | |
@Override | |
public void onComplete(@NonNull Task<QuerySnapshot> task) { | |
if (task.isSuccessful()) { | |
List<DocumentSnapshot> documentSnapshots = task.getResult().getDocuments(); | |
for (DocumentSnapshot documentSnapshot : documentSnapshots) { | |
ProductModel productModel = documentSnapshot.toObject(ProductModel.class); | |
vegetablesModel.add(productModel); | |
// progressbarUtils.hide(); | |
ProductAdapter productAdapter = new ProductAdapter(getActivity(), vegetablesModel); | |
vegetableListView.setAdapter(productAdapter); | |
} | |
} | |
} | |
}); | |
} | |
private List<OurServicesModel> ourServices() { | |
List<OurServicesModel> ourServicesModels = new ArrayList<>(); | |
ourServicesModels.add(new OurServicesModel(R.drawable.ic_delivery, "Free Shipping")); | |
ourServicesModels.add(new OurServicesModel(R.drawable.ic_reload, "Free Return")); | |
ourServicesModels.add(new OurServicesModel(R.drawable.ic_support, "24/7 Support")); | |
ourServicesModels.add(new OurServicesModel(R.drawable.ic_sale, "Daily Offer")); | |
return ourServicesModels; | |
} | |
private void setPopularProduct() { | |
final List<ProductModel> popularProduct = new ArrayList<>(); | |
firebaseFirestore.collection(OpenHelper.PRODUCT).limit(4).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { | |
@Override | |
public void onComplete(@NonNull Task<QuerySnapshot> task) { | |
if (task.isSuccessful()) { | |
List<DocumentSnapshot> documentSnapshots = task.getResult().getDocuments(); | |
for (DocumentSnapshot documentSnapshot : documentSnapshots) { | |
ProductModel productModel = documentSnapshot.toObject(ProductModel.class); | |
popularProduct.add(productModel); | |
ProductAdapter productAdapter = new ProductAdapter(getActivity(), popularProduct); | |
popularProductListView.setAdapter(productAdapter); | |
// progressbarUtils.hide(); | |
} | |
} | |
} | |
}); | |
} | |
private void setFruitsItem() { | |
final List<ProductModel> fruitModel = new ArrayList<>(); | |
firebaseFirestore.collection(OpenHelper.PRODUCT).whereEqualTo("productCategory", "Fruits").limit(4).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { | |
@Override | |
public void onComplete(@NonNull Task<QuerySnapshot> task) { | |
if (task.isSuccessful()) { | |
List<DocumentSnapshot> documentSnapshots = task.getResult().getDocuments(); | |
for (DocumentSnapshot documentSnapshot : documentSnapshots) { | |
ProductModel productModel = documentSnapshot.toObject(ProductModel.class); | |
fruitModel.add(productModel); | |
// progressbarUtils.hide(); | |
ProductAdapter fruitsAdapter = new ProductAdapter(getActivity(), fruitModel); | |
fruitsListView.setAdapter(fruitsAdapter); | |
} | |
} | |
} | |
}); | |
} | |
private List<SliderModel> specialOfferSlider() { | |
List<SliderModel> offerSliderModel = new ArrayList<>(); | |
offerSliderModel.add(new SliderModel("https://www.jiomart.com/images/cms/offers/1594388215_HDFC-offer-910px_380px.jpg")); | |
offerSliderModel.add(new SliderModel("https://i0.wp.com/www.indiagetfreestuff.com/wp-content/uploads/2020/07/JioMart-SBI-Offer.png?resize=303%2C303")); | |
offerSliderModel.add(new SliderModel("https://www.hogwired.com/promocode/wp-content/uploads/2018/01/booking.com-bank-offers.png")); | |
offerSliderModel.add(new SliderModel("https://content.coins.ph/wp-content/uploads/2019/05/rainyslider_v1_10loadcashback.png")); | |
return offerSliderModel; | |
} | |
private List<SliderModel> cashBackOffer(){ | |
List<SliderModel> cashBackSlider = new ArrayList<>(); | |
cashBackSlider.add(new SliderModel("https://www.hogwired.com/promocode/wp-content/uploads/2018/01/booking.com-bank-offers.png")); | |
cashBackSlider.add(new SliderModel("https://content.coins.ph/wp-content/uploads/2019/05/rainyslider_v1_10loadcashback.png")); | |
cashBackSlider.add(new SliderModel("https://www.jiomart.com/images/cms/offers/1594388215_HDFC-offer-910px_380px.jpg")); | |
cashBackSlider.add(new SliderModel("https://i0.wp.com/www.indiagetfreestuff.com/wp-content/uploads/2020/07/JioMart-SBI-Offer.png?resize=303%2C303")); | |
return cashBackSlider; | |
} | |
@Override | |
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { | |
inflater = getActivity().getMenuInflater(); | |
inflater.inflate(R.menu.navigation, menu); | |
super.onCreateOptionsMenu(menu, inflater); | |
} | |
@Override | |
public boolean onOptionsItemSelected(@NonNull MenuItem item) { | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment