-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a261853
commit c9d5136
Showing
20 changed files
with
779 additions
and
85 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/filehandling/lib/activities/HomeActivity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.filehandling.lib.activities | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import com.google.android.material.floatingactionbutton.FloatingActionButton | ||
import com.google.android.material.snackbar.Snackbar | ||
import com.google.android.material.tabs.TabLayout | ||
import androidx.viewpager.widget.ViewPager | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import androidx.lifecycle.Observer | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.filehandling.lib.FolderViewModel | ||
import com.filehandling.lib.R | ||
import com.filehandling.lib.activities.ui.main.PageViewModel | ||
import com.filehandling.lib.activities.ui.main.SectionsPagerAdapter | ||
|
||
class HomeActivity : AppCompatActivity() { | ||
|
||
lateinit var mPageViewModel: PageViewModel | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_home) | ||
|
||
mPageViewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(application) | ||
.create(PageViewModel::class.java) | ||
|
||
initActionBar() | ||
val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager) | ||
val viewPager: ViewPager = findViewById(R.id.view_pager) | ||
viewPager.adapter = sectionsPagerAdapter | ||
val tabs: TabLayout = findViewById(R.id.tabs) | ||
tabs.setupWithViewPager(viewPager) | ||
|
||
} | ||
|
||
private fun initActionBar() { | ||
supportActionBar?.apply { | ||
setHomeAsUpIndicator(R.drawable.ic_left_arrow) | ||
setHomeButtonEnabled(true) | ||
setDisplayHomeAsUpEnabled(true) | ||
setDisplayShowCustomEnabled(true) | ||
setDisplayShowTitleEnabled(true) | ||
} | ||
} | ||
|
||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
if (item.itemId == android.R.id.home) { | ||
val bundle = Bundle() | ||
bundle.putSerializable("file-list", mPageViewModel.fileList.value) | ||
val intent = Intent() | ||
intent.putExtra("file-bundle", bundle) | ||
setResult(Activity.RESULT_OK, intent) | ||
finish() | ||
return true | ||
} | ||
return super.onOptionsItemSelected(item) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/filehandling/lib/activities/ui/main/PageViewModel.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.filehandling.lib.activities.ui.main | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.Transformations | ||
import androidx.lifecycle.Transformations.map | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.filehandling.lib.models.CustomFileModel | ||
import com.filehandling.lib.models.LibFile | ||
|
||
class PageViewModel : ViewModel() { | ||
|
||
private val _index = MutableLiveData<Int>() | ||
val text: LiveData<String> = map(_index) { | ||
"Hello world from section: $it" | ||
} | ||
|
||
fun setIndex(index: Int) { | ||
_index.value = index | ||
} | ||
|
||
private val mChosenFileList = MutableLiveData<ArrayList<LibFile>>() | ||
val fileList: LiveData<ArrayList<LibFile>> = mChosenFileList | ||
|
||
fun addFile(file: LibFile) { | ||
if (mChosenFileList.value == null) { | ||
mChosenFileList.value = ArrayList() | ||
} | ||
if (!mChosenFileList.value!!.contains(file)) { | ||
val list = mChosenFileList.value | ||
list!!.add(file) | ||
mChosenFileList.postValue(list) | ||
} | ||
} | ||
|
||
fun removeFile(file: LibFile) { | ||
if (mChosenFileList.value != null && mChosenFileList.value!!.contains(file)) { | ||
val list = mChosenFileList.value | ||
list!!.remove(file) | ||
mChosenFileList.postValue(list) | ||
} | ||
} | ||
} |
Oops, something went wrong.