Rewrite SelectSiteScene
This commit is contained in:
1 parent
42f06ff84a
commit
3e500500e0
1 file changed
+46
-68
@@ -13,83 +13,61 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.scene
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.hippo.ehviewer.EhApplication.Companion.ehCookieStore
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.databinding.SceneSelectSiteBinding
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
class SelectSiteScene : BaseScene() {
|
||||
private var _binding: SceneSelectSiteBinding? = null
|
||||
private val binding
|
||||
get() = _binding!!
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class SelectSiteScene extends BaseScene implements View.OnClickListener {
|
||||
|
||||
private MaterialButtonToggleGroup mButtonGroup;
|
||||
private View mOk;
|
||||
|
||||
@Override
|
||||
public boolean needShowLeftDrawer() {
|
||||
return false;
|
||||
override fun needShowLeftDrawer(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_select_site, container, false);
|
||||
|
||||
mButtonGroup = (MaterialButtonToggleGroup) ViewUtils.$$(view, R.id.button_group);
|
||||
if (EhApplication.getEhCookieStore().hasSignedIn()) {
|
||||
((MaterialButton) view.findViewById(R.id.site_ex)).setChecked(true);
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = SceneSelectSiteBinding.inflate(inflater, container, false)
|
||||
if (ehCookieStore.hasSignedIn()) {
|
||||
binding.siteEx.isChecked = true
|
||||
} else {
|
||||
((MaterialButton) view.findViewById(R.id.site_e)).setChecked(true);
|
||||
binding.siteE.isChecked = true
|
||||
}
|
||||
mOk = ViewUtils.$$(view, R.id.ok);
|
||||
binding.ok.setOnClickListener {
|
||||
when (binding.buttonGroup.checkedButtonId) {
|
||||
R.id.site_e -> {
|
||||
Settings.putSelectSite(false)
|
||||
Settings.putGallerySite(EhUrl.SITE_E)
|
||||
navigateToTop()
|
||||
}
|
||||
|
||||
mOk.setOnClickListener(this);
|
||||
R.id.site_ex -> {
|
||||
Settings.putSelectSite(false)
|
||||
Settings.putGallerySite(EhUrl.SITE_EX)
|
||||
navigateToTop()
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mButtonGroup = null;
|
||||
mOk = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity activity = getMainActivity();
|
||||
if (null == activity || null == mButtonGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v == mOk) {
|
||||
int id = mButtonGroup.getCheckedButtonId();
|
||||
if (id == R.id.site_e) {
|
||||
Settings.putSelectSite(false);
|
||||
Settings.putGallerySite(EhUrl.SITE_E);
|
||||
navigateToTop();
|
||||
} else if (id == R.id.site_ex) {
|
||||
Settings.putSelectSite(false);
|
||||
Settings.putGallerySite(EhUrl.SITE_EX);
|
||||
navigateToTop();
|
||||
} else {
|
||||
showTip(R.string.no_select, LENGTH_SHORT);
|
||||
else -> {
|
||||
showTip(R.string.no_select, LENGTH_SHORT)
|
||||
}
|
||||
}
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user