Last active
April 14, 2018 12:45
-
-
Save abduakhatov/5d936a5e87f3690cbfdd05ceefe440d7 to your computer and use it in GitHub Desktop.
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
class BottomBarAdapter : NavBarFragmentStatePagerAdapter<Fragment> { | |
private val fragments = ArrayList<Fragment>() | |
constructor(fm: FragmentManager?) : super(fm) | |
fun addFragments(fragment: Fragment) { | |
fragments.add(fragment) | |
} | |
override fun getItem(position: Int): Fragment { | |
return fragments.get(position); | |
} | |
override fun getCount(): Int { | |
return fragments.size; | |
} | |
} |
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
class CategorySearchFragment : Fragment() { | |
@BindView(R.id.rvSearchList) | |
lateinit var rvSearchList: RecyclerView | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
} | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle?): View? { | |
val view = inflater.inflate(R.layout.fragment_search_category, container, false) | |
ButterKnife.bind(this, view) | |
initAdapter() | |
return view | |
} | |
override fun onResume() { | |
super.onResume() | |
initAdapter() | |
} | |
override fun onDestroyView() { | |
super.onDestroyView() | |
rvSearchList.clearOnChildAttachStateChangeListeners() | |
rvSearchList.layoutManager = null | |
rvSearchList.adapter = null | |
} | |
private fun initAdapter() { | |
val adapter = SeachListAdapter(this.context, getData()) | |
val llManager = LinearLayoutManager(this.context) | |
rvSearchList.layoutManager = llManager | |
rvSearchList.adapter = adapter | |
} | |
private val data = arrayListOf<Organization>() | |
fun getData(): ArrayList<Organization> { | |
for (i in 0..orgs.size - 1) { | |
data.add(Organization(orgs[i], location[i], distance[i], openClosed[i])) | |
} | |
return data | |
} | |
private val openClosed = booleanArrayOf(true, false, true, false, true, false, true, false) | |
private val orgs = arrayOf("Organization One", "Organization Two", | |
"Organization Three", "Organization Four", "Organization Five", | |
"Organization Six", "Organization Seven", "Organization Eight") | |
private val location = arrayOf("Tashkent, Uzbekistan", "Shymkent, Kazakhstan", | |
"Tashkent, Uzbekistan", "Tashkent, Uzbekistan", | |
"Samarkand, Uzbekistan", "Fergana, Uzbekistan", | |
"Namangan, Uzbekistan", "Tashkent, Uzbekistan") | |
private val distance = floatArrayOf(1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f) | |
} |
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
private lateinit var pagerAdapter: BottomBarAdapter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.content_main) | |
setupViewPager() | |
} | |
private fun setupViewPager() { | |
viewPager.setPagingEnabled(false); | |
pagerAdapter = BottomBarAdapter(getSupportFragmentManager()) | |
pagerAdapter.addFragments(HomeFragment.newInstance()); | |
pagerAdapter.addFragments(SearchFragment.newInstance()); | |
pagerAdapter.addFragments(BookmarkFragment.newInstance()); | |
pagerAdapter.addFragments(MyProfileFragment.newInstance()); | |
viewPager.setAdapter(pagerAdapter); | |
} |
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
class SearchFragment : Fragment() { | |
@BindView(R.id.vpSearch) | |
lateinit var vpSearch: ViewPager | |
@BindView(R.id.tlSearch) | |
lateinit var tlSearch: TabLayout | |
@BindView(R.id.llWorkingContainer) | |
lateinit var llWorkingContainer: RelativeLayout | |
@BindView(R.id.llGradContainer) | |
lateinit var llGradContainer: LinearLayout | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
} | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle?): View? { | |
val view = inflater.inflate(R.layout.fragment_search, container, false) as View | |
ButterKnife.bind(this, view) | |
val adapter = SearchVPAdapter(fragmentManager) | |
adapter.addFragment(CategorySearchFragment(), "Category") | |
adapter.addFragment(NameSearchFragment(), "Name") | |
adapter.addFragment(MapSearchFragment(), "Map") | |
vpSearch.adapter = adapter | |
tlSearch.setupWithViewPager(vpSearch) | |
initUI() | |
return view | |
} | |
private fun initUI() { | |
RevelyGradient.linear() | |
.angle(-45f) | |
.colors(Constants.arrOfColsBelowToolbar) | |
.onBackgroundOf(llGradContainer) | |
} | |
override fun onDetach() { | |
super.onDetach() | |
} | |
override fun onDestroyView() { | |
super.onDestroyView() | |
// rvSearchList.clearOnChildAttachStateChangeListeners() | |
// rvSearchList.layoutManager = null | |
// rvSearchList.adapter = null | |
} | |
companion object { | |
@JvmStatic | |
fun newInstance() = SearchFragment() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment