Created
October 26, 2020 12:08
-
-
Save MahmoudAymann/c2c0be3497f96c2a5c2b8cb281b37044 to your computer and use it in GitHub Desktop.
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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<androidx.fragment.app.FragmentContainerView | |
android:id="@+id/auth_fragment" | |
android:name="androidx.navigation.fragment.NavHostFragment" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
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
<activity | |
android:name="com.tarashly.user.ui.activity.DialogActivity" | |
android:theme="@style/DialogActivityTheme"/> |
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
<?xml | |
version="1.0" | |
encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/transparent"> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:background="@drawable/et_background" | |
android:paddingBottom="@dimen/_24sdp" | |
android:layout_marginBottom="@dimen/_36sdp" | |
android:layout_marginEnd="@dimen/_16sdp" | |
android:layout_marginStart="@dimen/_16sdp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintHorizontal_bias="0.5" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent"> | |
<TextView | |
android:id="@+id/textView7" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="24dp" | |
android:text="@string/error" | |
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintHorizontal_bias="0.5" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:id="@+id/tv_error" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="@dimen/_8sdp" | |
android:gravity="center" | |
android:paddingStart="@dimen/_16sdp" | |
android:paddingEnd="@dimen/_16sdp" | |
tools:text="@string/invalid_email" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintHorizontal_bias="0.5" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/textView7" /> | |
<com.google.android.material.button.MaterialButton | |
android:id="@+id/btn_ok" | |
style="@style/SubmitButtonStyle" | |
android:layout_width="@dimen/_100sdp" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="@dimen/_8sdp" | |
android:text="@string/ok" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintHorizontal_bias="0.5" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/tv_error" /> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
</layout> |
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
package com.tarashly.user.ui.activity; | |
import android.content.Context; | |
import android.os.Bundle; | |
import androidx.annotation.Nullable; | |
import androidx.fragment.app.Fragment; | |
import androidx.fragment.app.FragmentActivity; | |
import androidx.fragment.app.FragmentManager; | |
import androidx.fragment.app.FragmentTransaction; | |
import com.tarashly.user.R; | |
import com.tarashly.user.data.Params; | |
import timber.log.Timber; | |
public class DialogActivity extends ParentActivity { | |
private void addFragment(String fragmentString, Bundle bundle) { | |
try { | |
Fragment fragment = (Fragment) (Class.forName(fragmentString).newInstance()); | |
fragment.setArguments(bundle); | |
replaceFragment(this, fragment, ""); | |
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) { | |
Timber.e("Fragment Not Found \n %s", e); | |
} | |
} | |
public void replaceFragment(Context context, Fragment fragment, String backStackText) { | |
try { | |
FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager(); | |
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().replace(R.id.auth_fragment, fragment); | |
if (!backStackText.equals("")) { | |
fragmentTransaction.addToBackStack(backStackText); | |
} | |
fragmentTransaction.commit(); | |
} catch (Exception e) { | |
//Timber.e(e); | |
} | |
} | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_dialog); | |
if (getIntent().hasExtra(Params.INTENT_PAGE_DIALOG)) { | |
addFragment(getIntent().getStringExtra(Params.INTENT_PAGE_DIALOG), | |
getIntent().getBundleExtra(Params.BUNDLE_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
package com.tarashly.user.ui.dialog; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
import androidx.fragment.app.DialogFragment; | |
import com.tarashly.user.data.Params; | |
import com.tarashly.user.databinding.DialogErrorBinding; | |
import com.tarashly.user.ui.fragment.BaseFragment; | |
import com.tarashly.user.utils.AppUtil; | |
public class ErrorDialog extends BaseFragment { | |
DialogErrorBinding binding; | |
String msg; | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (getArguments()!=null){ | |
if (getArguments().containsKey(Params.MESSAGE)){ | |
msg = getArguments().getString(Params.MESSAGE); | |
} | |
} | |
} | |
@Nullable | |
@Override | |
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
binding = DialogErrorBinding.inflate(inflater, container, false); | |
binding.tvError.setText(msg); | |
binding.btnOk.setOnClickListener(v -> { | |
closeFragment(); | |
}); | |
return binding.getRoot(); | |
} | |
} |
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
<style name="DialogActivityTheme" parent="AppTheme"> | |
<item name="android:windowIsTranslucent">true</item> | |
<item name="android:windowBackground">@android:color/transparent</item> | |
<item name="android:windowContentOverlay">@null</item> | |
<item name="android:windowNoTitle">true</item> | |
<!--<item name="android:windowIsFloating">true</item> <!–act like dialog–>--> | |
<item name="android:backgroundDimEnabled">true</item> | |
<item name="windowActionBar">false</item> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment