-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,879 additions
and
437 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
82 changes: 82 additions & 0 deletions
82
affirm/src/main/java/com/affirm/android/AffirmFragment.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.affirm.android; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.IdRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.fragment.app.FragmentManager; | ||
|
||
abstract class AffirmFragment extends Fragment implements AffirmWebChromeClient.Callbacks { | ||
|
||
protected static final String TAG_PREFIX = "AffirmFragment"; | ||
|
||
AffirmWebView webView; | ||
private View progressIndicator; | ||
|
||
abstract void initViews(); | ||
|
||
abstract void onAttached(); | ||
|
||
protected static void addFragment(FragmentManager fragmentManager, @IdRes int containerViewId, | ||
@NonNull Fragment fragment, @NonNull String tag) { | ||
fragmentManager | ||
.beginTransaction() | ||
.add(containerViewId, fragment, tag) | ||
.commitAllowingStateLoss(); | ||
fragmentManager.executePendingTransactions(); | ||
} | ||
|
||
protected void removeFragment(@NonNull String tag) { | ||
FragmentManager fragmentManager = getFragmentManager(); | ||
if (fragmentManager == null) { | ||
AffirmLog.d("The fragment is getting detached from the Activity"); | ||
return; | ||
} | ||
Fragment fragment = fragmentManager.findFragmentByTag(tag); | ||
if (fragment != null) { | ||
fragmentManager.beginTransaction().remove(fragment).commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setRetainInstance(true); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.affirm_fragment_webview, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
|
||
webView = view.findViewById(R.id.webview); | ||
progressIndicator = view.findViewById(R.id.progressIndicator); | ||
|
||
AffirmUtils.debuggableWebView(getContext()); | ||
initViews(); | ||
onAttached(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
webView.destroyWebView(); | ||
webView = null; | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void chromeLoadCompleted() { | ||
progressIndicator.setVisibility(View.GONE); | ||
} | ||
} |
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
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
Oops, something went wrong.