Skip to content

Commit

Permalink
Update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kirich1409 committed Sep 17, 2020
1 parent a9ff016 commit 6678f81
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 20 deletions.
17 changes: 14 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="by.kirich1409.viewbindingdelegate.sample">
package="by.kirich1409.viewbindingdelegate.sample"
>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" />
android:theme="@style/AppTheme"
>

</manifest>
<activity android:name=".ProfileActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
package by.kirich1409.viewbindingdelegate.sample

import androidx.appcompat.app.AppCompatActivity
import by.kirich1409.viewbindingdelegate.sample.databinding.ProfileBinding
import by.kirich1409.viewbindingdelegate.sample.databinding.ActivityProfileBinding
import by.kirich1409.viewbindingdelegate.viewBinding

class ProfileActivity : AppCompatActivity(R.layout.profile) {
class ProfileActivity : AppCompatActivity(R.layout.activity_profile) {

private val viewBindingUsingReflection: ProfileBinding by viewBinding(R.id.container)
private val viewBindingUsingReflection: ActivityProfileBinding by viewBinding(R.id.container)

private val viewBindingWithoutReflection by viewBinding(ProfileBinding::bind, R.id.container)
private val viewBindingWithoutReflection by viewBinding(ActivityProfileBinding::bind, R.id.container)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import by.kirich1409.viewbindingdelegate.dialogViewBinding
import by.kirich1409.viewbindingdelegate.sample.databinding.ProfileBinding
import by.kirich1409.viewbindingdelegate.sample.databinding.FragmentProfileBinding

class ProfileDialogFragment1 : DialogFragment() {

private val viewBindingUsingReflection: ProfileBinding by dialogViewBinding(R.id.container)
private val viewBindingUsingReflection: FragmentProfileBinding by dialogViewBinding(R.id.container)

private val viewBindingWithoutReflection by dialogViewBinding(ProfileBinding::bind, R.id.container)
private val viewBindingWithoutReflection by dialogViewBinding(FragmentProfileBinding::bind, R.id.container)

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialog.Builder(requireContext())
.setView(R.layout.profile)
.setView(R.layout.fragment_profile)
.create()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import by.kirich1409.viewbindingdelegate.sample.databinding.ProfileBinding
import by.kirich1409.viewbindingdelegate.viewBinding
import by.kirich1409.viewbindingdelegate.dialogViewBinding
import by.kirich1409.viewbindingdelegate.sample.databinding.FragmentProfileBinding

class ProfileDialogFragment2 : DialogFragment() {

private val viewBindingUsingReflection: ProfileBinding by dialogViewBinding(R.id.container)
private val viewBindingUsingReflection: FragmentProfileBinding by dialogViewBinding(R.id.container)

// Creating via default way will work too for that case
// private val viewBinding: ProfileBinding by viewBinding()

private val viewBindingWithoutReflection by viewBinding(ProfileBinding::bind)
private val viewBindingWithoutReflection by viewBinding(FragmentProfileBinding::bind)

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.profile, container, false)
return inflater.inflate(R.layout.fragment_profile, container, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
package by.kirich1409.viewbindingdelegate.sample

import androidx.fragment.app.Fragment
import by.kirich1409.viewbindingdelegate.sample.databinding.ProfileBinding
import by.kirich1409.viewbindingdelegate.sample.databinding.FragmentProfileBinding
import by.kirich1409.viewbindingdelegate.viewBinding

class ProfileFragment : Fragment(R.layout.profile) {
class ProfileFragment : Fragment(R.layout.fragment_profile) {

private val viewBindingUsingReflection: ProfileBinding by viewBinding()
private val viewBindingUsingReflection: FragmentProfileBinding by viewBinding()

private val viewBindingWithoutReflection by viewBinding(ProfileBinding::bind)
private val viewBindingWithoutReflection by viewBinding(FragmentProfileBinding::bind)

override fun onDestroyView() {
super.onDestroyView()
viewBindingUsingReflection.container.visibility
}
}
17 changes: 17 additions & 0 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<fragment
android:name="by.kirich1409.viewbindingdelegate.sample.ProfileFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_profile"
/>

</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp"
>

<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Profile"
android:textAppearance="?android:textAppearanceLarge"
/>

<ImageView
android:id="@+id/icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:src="#F0F"
/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
/>

</LinearLayout>
</LinearLayout>

0 comments on commit 6678f81

Please sign in to comment.