Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send the variant as an argument to second fragment #82

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ class FirstFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

binding.buttonFirst.setOnClickListener {
if (unleashClient.isEnabled("unleash_first_fragment_demo")) {
findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
if (unleashClient.isEnabled("android-sdk-first-fragment-demo")) {
val bundle = Bundle()
val variant = unleashClient.getVariant("android-sdk-first-fragment-demo")
bundle.putString("argName", variant.payload?.getValueAsString() ?: variant.name)
findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment, bundle)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
Expand All @@ -15,14 +14,6 @@ import com.example.unleash.databinding.ActivityMainBinding
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import io.getunleash.UnleashClient
import io.getunleash.UnleashConfig
import io.getunleash.UnleashContext
import io.getunleash.cache.InMemoryToggleCache
import io.getunleash.polling.PollingModes
import java.time.Duration
import java.time.temporal.ChronoUnit
import java.time.temporal.TemporalUnit
import kotlin.random.Random

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.navigation.fragment.findNavController
import com.example.unleash.databinding.FragmentSecondBinding
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -39,8 +40,11 @@ class SecondFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val args = arguments?.getString("argName") ?: "No Args"
view.findViewById<TextView>(R.id.textview_second).text = getString(R.string.hello_second_fragment, args)

binding.buttonSecond.setOnClickListener {
if (unleashClient.isEnabled("unleash_second_fragment")) {
if (unleashClient.isEnabled("android-sdk-second-fragment-demo")) {
findNavController().navigate(R.id.action_SecondFragment_to_FirstFragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ internal object UnleashClientModule {
.appName("unleash-android")
.instanceId("unleash-android-${Random.nextLong()}")
.enableMetrics()
.clientKey("get a frontend key from instance you connect to")
.proxyUrl("http:///UNLEASHURL:4242/api/frontend")
.clientKey("default:development.5d6b7aaeb6a9165f28e91290d13ba0ed39f56f6d9e6952c642fed7cc")
.proxyUrl("https://eu.app.unleash-hosted.com/demo/api/frontend")
.pollingMode(
PollingModes.autoPoll(
autoPollIntervalSeconds = 15
Expand Down
2 changes: 2 additions & 0 deletions samples/android/app/src/main/res/layout/fragment_second.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
android:layout_height="match_parent"
tools:context=".SecondFragment">


<TextView
android:id="@+id/textview_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_second_fragment"
app:layout_constraintBottom_toTopOf="@id/button_second"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
4 changes: 4 additions & 0 deletions samples/android/app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
android:label="@string/second_fragment_label"
tools:layout="@layout/fragment_second">

<argument
android:name="argName"
app:argType="string" />

<action
android:id="@+id/action_SecondFragment_to_FirstFragment"
app:destination="@id/FirstFragment" />
Expand Down
Loading