diff --git a/app/build.gradle b/app/build.gradle index d28d2ae..e6f7f8b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "io.github.yueeng.hacg" minSdkVersion 14 targetSdkVersion 23 - versionCode 11 - versionName "1.0.7.1" + versionCode 12 + versionName "1.0.8" multiDexEnabled true testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner" } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index db154de..b302b12 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -23,6 +23,12 @@ app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> + + + val lp = ad.getLayoutParams + val p = new Point() + d.getSize(p) + lp.height = Math.min(p.x * 225 / 550, p.y / 3) + ad.setLayoutParams(lp) + p.x < p.y + case _ => ad.setVisibility(View.GONE); false + } + ad.setAdapter(new AdAdapter(crop)) + + ad.addOnPageChangeListener(new SimpleOnPageChangeListener { + override def onPageScrollStateChanged(state: Int): Unit = { + state match { + case ViewPager.SCROLL_STATE_DRAGGING => adstop() + case ViewPager.SCROLL_STATE_IDLE => adstart() + case _ => + } + } + }) //hack align tab by left tabs.smoothScrollTo(0, 0) checkVersion(false) } + override def onPause(): Unit = { + super.onPause() + adstop() + } + + + override def onResume(): Unit = { + super.onResume() + adstart() + } + + val adspan = 5000 + + def adstart() = { + ad.removeCallbacks(adrun) + ad.postDelayed(adrun, adspan) + } + + def adstop() = ad.removeCallbacks(adrun) + + def adchange(): Unit = { + ad.setCurrentItem(ad.getCurrentItem + 1 match { + case x if x >= ad.getAdapter.getCount => 0 + case x => x + }) + ad.postDelayed(adrun, adspan) + } + + val adrun: Runnable = runnable { () => + ad.setCurrentItem(ad.getCurrentItem + 1 match { + case x if x >= ad.getAdapter.getCount => 0 + case x => x + }) + ad.postDelayed(adrun, adspan) + } + + class AdAdapter(crop: Boolean) extends PagerAdapter { + override def isViewFromObject(view: View, `object`: scala.Any): Boolean = view == `object` + + override def getCount: Int = 4 + + override def instantiateItem(container: ViewGroup, position: Int): AnyRef = { + val image = new ImageView(container.getContext) + image.setAdjustViewBounds(true) + if (crop) image.setScaleType(ScaleType.CENTER_CROP) + image.setOnClickListener(viewClick { v => Common.openWeb(MainActivity.this, s"http://hacg.club/gg/${position + 1}") }) + Picasso.`with`(container.getContext).load(s"http://hacg.club/gg/${position + 1}.jpg").into(image) + container.addView(image) + image + } + + override def destroyItem(container: ViewGroup, position: Int, `object`: scala.Any): Unit = { + container.removeView(`object`.asInstanceOf[View]) + } + } + override def onBackPressed(): Unit = { Snackbar.make(findViewById(R.id.coordinator), R.string.app_exit_confirm, Snackbar.LENGTH_SHORT) .setAction(R.string.app_exit, viewClick { v => ActivityCompat.finishAfterTransition(MainActivity.this) })