-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
8 changed files
with
249 additions
and
15 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
97 changes: 97 additions & 0 deletions
97
app/src/main/java/soko/ekibun/bangumi/ui/subject/EditProgressDialog.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,97 @@ | ||
package soko.ekibun.bangumi.ui.subject | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.Rect | ||
import android.os.Bundle | ||
import android.support.v4.app.DialogFragment | ||
import android.support.v7.app.AppCompatActivity | ||
import android.util.DisplayMetrics | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.WindowManager | ||
import kotlinx.android.synthetic.main.dialog_edit_progress.view.* | ||
import okhttp3.FormBody | ||
import soko.ekibun.bangumi.R | ||
import soko.ekibun.bangumi.api.ApiHelper | ||
import soko.ekibun.bangumi.api.bangumi.Bangumi | ||
import soko.ekibun.bangumi.api.bangumi.bean.Subject | ||
|
||
class EditProgressDialog: DialogFragment() { | ||
companion object { | ||
fun showDialog(context: AppCompatActivity, subject: Subject, formhash: String, ua: String, callback: ()->Unit){ | ||
val dialog = EditProgressDialog() | ||
dialog.subject = subject | ||
dialog.formhash = formhash | ||
dialog.callback = callback | ||
dialog.ua = ua | ||
dialog.show(context.supportFragmentManager, "edit_progress") | ||
} | ||
} | ||
|
||
private fun getKeyBoardHeight(): Int{ | ||
val rect = Rect() | ||
activity?.window?.decorView?.getWindowVisibleDisplayFrame(rect) | ||
val metrics = DisplayMetrics() | ||
(activity?.getSystemService(Context.WINDOW_SERVICE) as? WindowManager)?.defaultDisplay?.getMetrics(metrics) | ||
return metrics.heightPixels - rect.bottom | ||
} | ||
|
||
lateinit var subject: Subject | ||
lateinit var formhash: String | ||
lateinit var ua: String | ||
lateinit var callback: ()->Unit | ||
@SuppressLint("SetTextI18n") | ||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
val view = inflater.inflate(R.layout.dialog_edit_progress, container) | ||
|
||
view.item_eps.setText(subject.ep_status.toString()) | ||
view.item_eps_info.text = "${ if(subject.eps_count == 0) "" else "/${subject.eps_count}" } 话" | ||
view.item_vol.setText(subject.vol_status.toString()) | ||
view.item_vol_info.text = "${ if(subject.vol_count == 0) "" else "/${subject.vol_count}" } 章" | ||
view.item_vol_panel.visibility = if(subject.has_vol) View.VISIBLE else View.GONE | ||
|
||
view.item_outside.setOnClickListener { | ||
dialog.dismiss() | ||
} | ||
view.item_submit.setOnClickListener { | ||
dialog.dismiss() | ||
val body = FormBody.Builder() | ||
.add("referer", "subject") | ||
.add("submit", "更新") | ||
.add("watchedeps", view.item_eps.text.toString()) | ||
if(subject.has_vol) body.add("watched_vols", view.item_vol.text.toString()) | ||
|
||
ApiHelper.buildHttpCall("${Bangumi.SERVER}/subject/set/watched/${subject.id}", mapOf("User-Agent" to ua), body.build()){ | ||
it.code() == 200 | ||
}.enqueue(ApiHelper.buildCallback(context,{ | ||
if(!it) return@buildCallback | ||
subject.ep_status = view.item_eps.text.toString().toIntOrNull()?:0 | ||
subject.vol_status = view.item_vol.text.toString().toIntOrNull()?:0 | ||
callback() | ||
},{})) | ||
} | ||
|
||
activity?.window?.decorView?.viewTreeObserver?.addOnGlobalLayoutListener{ | ||
view.item_keyboard.layoutParams?.let{ | ||
it.height = getKeyBoardHeight() | ||
view.item_keyboard.layoutParams = it | ||
} | ||
} | ||
|
||
dialog.window?.attributes?.let{ | ||
it.dimAmount = 0.6f | ||
dialog.window?.attributes = it | ||
} | ||
dialog.window?.setWindowAnimations(R.style.AnimDialog) | ||
dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) | ||
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) | ||
return view | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_Dialog) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical"> | ||
<View android:layout_height="0dp" | ||
android:layout_weight="1" | ||
android:layout_width="match_parent" | ||
android:id="@+id/item_outside"/> | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="12dp" | ||
android:background="?android:colorBackground" | ||
android:orientation="vertical"> | ||
<LinearLayout | ||
android:id="@+id/item_eps_panel" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
<EditText | ||
android:id="@+id/item_eps" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:inputType="number" | ||
android:maxLines="1"/> | ||
<TextView | ||
android:id="@+id/item_eps_info" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="8dp"/> | ||
</LinearLayout> | ||
<LinearLayout | ||
android:id="@+id/item_vol_panel" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
<EditText | ||
android:id="@+id/item_vol" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:inputType="number" | ||
android:maxLines="1"/> | ||
<TextView | ||
android:id="@+id/item_vol_info" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="8dp"/> | ||
</LinearLayout> | ||
<LinearLayout | ||
android:id="@+id/item_buttons" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
<View android:layout_weight="1" | ||
android:layout_height="match_parent" | ||
android:layout_width="0dp"/> | ||
<TextView | ||
android:id="@+id/item_submit" | ||
android:layout_width="wrap_content" | ||
android:tint="?android:textColorSecondary" | ||
android:padding="12dp" | ||
android:tintMode="src_in" | ||
android:background="?android:attr/selectableItemBackground" | ||
android:layout_height="wrap_content" | ||
android:textColor="?colorAccent" | ||
android:text="更新"/> | ||
</LinearLayout> | ||
<View android:id="@+id/item_keyboard" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp"/> | ||
</LinearLayout> | ||
</LinearLayout> |