Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ddbd1b5 authored by jo's avatar jo
Browse files
parents 56cdb636 cde66e44
Loading
Loading
Loading
Loading
+30 −9
Original line number Diff line number Diff line
@@ -18,11 +18,12 @@ import io.eelo.appinstaller.search.SearchFragment
import io.eelo.appinstaller.settings.SettingsFragment
import io.eelo.appinstaller.updates.UpdatesFragment
import io.eelo.appinstaller.utils.Common
import io.eelo.appinstaller.utils.Constants.CURRENTLY_SELECTED_FRAGMENT_KEY
import io.eelo.appinstaller.utils.Constants.STORAGE_PERMISSION_REQUEST_CODE
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener {
    private var currentFragment: Fragment? = null
    private var currentFragmentId = 0
    private val homeFragment = HomeFragment()
    private val categoriesFragment = CategoriesFragment()
    private val searchFragment = SearchFragment()
@@ -38,7 +39,15 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
            val installManager = installManagerGetter.connectAndGet(this)
            initialiseFragments(installManager)
            // Show the home fragment by default
            showFragment(homeFragment)
            if (savedInstanceState != null) {
                if (selectFragment(savedInstanceState.getInt(CURRENTLY_SELECTED_FRAGMENT_KEY))) {
                    currentFragmentId = savedInstanceState.getInt(CURRENTLY_SELECTED_FRAGMENT_KEY)
                }
            } else {
                if (selectFragment(R.id.menu_home)) {
                    currentFragmentId = R.id.menu_home
                }
            }
        }

        bottom_navigation_view.setOnNavigationItemSelectedListener(this)
@@ -52,24 +61,32 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
    }

    override fun onNavigationItemSelected(item: MenuItem): Boolean {
        when {
            item.itemId == R.id.menu_home -> {
        if (selectFragment(item.itemId)) {
            currentFragmentId = item.itemId
            return true
        }
        return false
    }

    private fun selectFragment(fragmentId: Int): Boolean {
        when (fragmentId) {
            R.id.menu_home -> {
                showFragment(homeFragment)
                return true
            }
            item.itemId == R.id.menu_categories -> {
            R.id.menu_categories -> {
                showFragment(categoriesFragment)
                return true
            }
            item.itemId == R.id.menu_search -> {
            R.id.menu_search -> {
                showFragment(searchFragment)
                return true
            }
            item.itemId == R.id.menu_updates -> {
            R.id.menu_updates -> {
                showFragment(updatesFragment)
                return true
            }
            item.itemId == R.id.menu_settings -> {
            R.id.menu_settings -> {
                showFragment(settingsFragment)
                return true
            }
@@ -82,7 +99,6 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
                .beginTransaction()
                .replace(R.id.frame_layout, fragment)
                .commit()
        currentFragment = fragment
    }

    @SuppressLint("RestrictedApi")
@@ -112,6 +128,11 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
        }
    }

    override fun onSaveInstanceState(outState: Bundle?) {
        super.onSaveInstanceState(outState)
        outState?.putInt(CURRENTLY_SELECTED_FRAGMENT_KEY, currentFragmentId)
    }

    override fun onDestroy() {
        super.onDestroy()
        installManagerGetter.disconnect(this)
+15 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package io.eelo.appinstaller.categories

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.content.res.Configuration
import android.os.Bundle
import android.support.v4.app.Fragment
import android.text.TextUtils
@@ -60,6 +61,18 @@ class CategoriesFragment : Fragment() {
        itemParams.marginStart = itemPadding
        itemParams.marginEnd = itemPadding

        // Check device orientation and increase/decrease number of columns
        val orientation = resources.configuration.orientation
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            // In landscape
            applicationsCategoriesList.columnCount = 3
            gamesCategoriesList.columnCount = 3
        } else {
            // In portrait
            applicationsCategoriesList.columnCount = 2
            gamesCategoriesList.columnCount = 2
        }

        // Bind to the list of applications categories
        categoriesViewModel.getApplicationsCategories().observe(this, Observer {
            showApplicationsCategories()
@@ -94,7 +107,7 @@ class CategoriesFragment : Fragment() {
            textView.setBackgroundResource(outValue.resourceId)
            applicationsCategoriesList.addView(textView)
            textView.setOnClickListener { _ ->
                categoriesViewModel.onCategoryClick(context!!, it, false)
                categoriesViewModel.onCategoryClick(context!!, it)
            }
            categoriesContainer.visibility = View.VISIBLE
            progressBar.visibility = View.GONE
@@ -122,7 +135,7 @@ class CategoriesFragment : Fragment() {
            textView.setBackgroundResource(outValue.resourceId)
            gamesCategoriesList.addView(textView)
            textView.setOnClickListener { _ ->
                categoriesViewModel.onCategoryClick(context!!, it, true)
                categoriesViewModel.onCategoryClick(context!!, it)
            }
            categoriesContainer.visibility = View.VISIBLE
            progressBar.visibility = View.GONE
+2 −7
Original line number Diff line number Diff line
@@ -36,14 +36,9 @@ class CategoriesViewModel : ViewModel(), CategoriesViewModelInterface {
        categoriesModel.loadCategories()
    }

    override fun onCategoryClick(context: Context, category: Category, isGame: Boolean) {
    override fun onCategoryClick(context: Context, category: Category) {
        val intent = Intent(context, CategoryActivity::class.java)
        if (isGame) {
            val gameCategory = Category(category.title, "game_" + category.id)
            intent.putExtra(Constants.CATEGORY_KEY, gameCategory)
        } else {
        intent.putExtra(Constants.CATEGORY_KEY, category)
        }
        context.startActivity(intent)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -12,5 +12,5 @@ interface CategoriesViewModelInterface {

    fun loadCategories()

    fun onCategoryClick(context: Context, category: Category, isGame: Boolean)
    fun onCategoryClick(context: Context, category: Category)
}
+3 −0
Original line number Diff line number Diff line
@@ -17,4 +17,7 @@ object Constants {

    // Categories
    const val CATEGORY_KEY = "category_key"

    // Home
    const val CURRENTLY_SELECTED_FRAGMENT_KEY = "currently_selected_fragment"
}
Loading