-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redo TV Files view to be a stack of folders, similar to phone
- Loading branch information
Showing
17 changed files
with
388 additions
and
319 deletions.
There are no files selected for viewing
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
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
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/stevenschoen/putionew/tv/HorizontalStackLayout.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,43 @@ | ||
package com.stevenschoen.putionew.tv | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.stevenschoen.putionew.R | ||
import com.stevenschoen.putionew.UIUtils | ||
|
||
class HorizontalStackLayout : ViewGroup { | ||
|
||
constructor(context: Context) : super(context) | ||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) | ||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) | ||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) | ||
|
||
val layerOffset by lazy { resources.getDimensionPixelSize(R.dimen.tv_layer_offset) } | ||
val layerElevation by lazy { resources.getDimension(R.dimen.tv_layer_elevation) } | ||
|
||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { | ||
val childLeft = paddingLeft; | ||
val childTop = paddingTop; | ||
val childRight = measuredWidth - paddingRight; | ||
val childBottom = measuredHeight - paddingBottom; | ||
val childWidth = childRight - childLeft; | ||
val childHeight = childBottom - childTop; | ||
|
||
for (i in 0..childCount - 1) { | ||
val child = getChildAt(i) | ||
val offset = (i * layerOffset) | ||
child.measure(MeasureSpec.makeMeasureSpec(childWidth - offset, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY)); | ||
child.layout(childLeft + offset, childTop, childRight, childBottom) | ||
if (UIUtils.hasLollipop()) { | ||
child.elevation = (i * layerElevation) | ||
} | ||
} | ||
} | ||
|
||
// Hacky, but without it sometimes the d-pad can go to the wrong page and become stuck | ||
override fun focusSearch(focused: View?, direction: Int): View? { | ||
return null | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
app/src/main/java/com/stevenschoen/putionew/tv/TvActivity.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
app/src/main/java/com/stevenschoen/putionew/tv/TvActivity.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,98 @@ | ||
package com.stevenschoen.putionew.tv | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.support.v4.app.Fragment | ||
import android.support.v4.app.FragmentActivity | ||
import com.stevenschoen.putionew.LoginActivity | ||
import com.stevenschoen.putionew.PutioApplication | ||
import com.stevenschoen.putionew.R | ||
import com.stevenschoen.putionew.model.files.PutioFile | ||
import rx.subjects.BehaviorSubject | ||
import java.util.* | ||
|
||
class TvActivity : FragmentActivity() { | ||
|
||
companion object { | ||
fun makeFolderFragTag(folder: PutioFile) = "folder_${folder.id}" | ||
} | ||
|
||
val displayedFolders = ArrayList<PutioFile>() | ||
val folders by lazy { BehaviorSubject.create<List<PutioFile>>(listOf(PutioFile.makeRootFolder(resources))) } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
val application = application as PutioApplication | ||
if (application.isLoggedIn) { | ||
init() | ||
} else { | ||
val setupIntent = Intent(this, LoginActivity::class.java) | ||
startActivity(setupIntent) | ||
finish() | ||
return | ||
} | ||
} | ||
|
||
fun init() { | ||
setContentView(R.layout.tv_activity) | ||
|
||
val stackView = findViewById(R.id.tv_stack) as HorizontalStackLayout | ||
|
||
fun addFolder(folder: PutioFile) { | ||
supportFragmentManager.beginTransaction() | ||
.add(R.id.tv_stack, TvFolderFragment.newInstance(this@TvActivity, folder), makeFolderFragTag(folder)) | ||
.commitNow() | ||
displayedFolders.add(folder) | ||
} | ||
|
||
fun removeLastFolder() { | ||
val lastFolder = displayedFolders.last() | ||
supportFragmentManager.beginTransaction() | ||
.remove(supportFragmentManager.findFragmentByTag(makeFolderFragTag(lastFolder))) | ||
.commitNow() | ||
displayedFolders.removeAt(displayedFolders.lastIndex) | ||
} | ||
|
||
addFolder(PutioFile.makeRootFolder(resources)) | ||
|
||
folders.subscribe { newFolders -> | ||
while (displayedFolders.size > newFolders.size) { | ||
removeLastFolder() | ||
} | ||
for ((index, newFolder) in newFolders.withIndex()) { | ||
if (index <= displayedFolders.lastIndex) { | ||
val displayedFolder = displayedFolders[index] | ||
if (newFolder.id != displayedFolder.id) { | ||
(index..displayedFolders.lastIndex).forEach { removeLastFolder() } | ||
} | ||
} else { | ||
addFolder(newFolder) | ||
} | ||
} | ||
getLastFolderFragment().requestFocusWhenPossible = true | ||
} | ||
} | ||
|
||
override fun onAttachFragment(fragment: Fragment) { | ||
super.onAttachFragment(fragment) | ||
if (fragment is TvFolderFragment) { | ||
fragment.onFolderSelected = { folder -> | ||
folders.onNext(folders.value.plus(folder)) | ||
} | ||
} | ||
} | ||
|
||
fun getLastFolderFragment() = supportFragmentManager.findFragmentByTag(makeFolderFragTag(displayedFolders.last())) as TvFolderFragment | ||
|
||
override fun onBackPressed() { | ||
if (displayedFolders.size > 1) { | ||
val lastFolderFragment = supportFragmentManager.findFragmentByTag(makeFolderFragTag(displayedFolders.last())) | ||
if (lastFolderFragment != null && lastFolderFragment is TvFolderFragment) { | ||
folders.onNext(folders.value.dropLast(1)) | ||
} | ||
} else { | ||
super.onBackPressed() | ||
} | ||
} | ||
} |
Oops, something went wrong.