Skip to content

Commit

Permalink
fix ContextThemeWrapper Crash...
Browse files Browse the repository at this point in the history
  • Loading branch information
abduelrahman committed Mar 27, 2020
1 parent 09e96a4 commit 18c817d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 78 deletions.
8 changes: 4 additions & 4 deletions leon/src/main/java/am/leon/OnImageClickListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import android.content.Context;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

import static am.leon.Utils.unwrap;

class OnImageClickListener implements View.OnClickListener, FullScreenPhotoFragment.FullScreenStatus {

private View view;
Expand Down Expand Up @@ -42,9 +42,9 @@ void setMedia(List<String> mediaList, int currentPosition, String appLanguage) {
public void onClick(View view) {
this.view = view;
if (media != null)
FullScreenPhotoFragment.getInstance(media, this).show(((AppCompatActivity) context).getSupportFragmentManager(), getClass().getName());
FullScreenPhotoFragment.getInstance(media, this).show(unwrap(context).getSupportFragmentManager(), getClass().getName());
else if (mediaList != null)
FullScreenPhotoFragment.getInstance(mediaList, currentPosition, appLanguage, this).show(((AppCompatActivity) context).getSupportFragmentManager(), getClass().getName());
FullScreenPhotoFragment.getInstance(mediaList, currentPosition, appLanguage, this).show(unwrap(context).getSupportFragmentManager(), getClass().getName());
}


Expand Down
13 changes: 13 additions & 0 deletions leon/src/main/java/am/leon/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.util.DisplayMetrics;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ContextThemeWrapper;

import java.util.Locale;

class Utils {
Expand All @@ -24,6 +28,15 @@ static void youtubePlay(Context context, String id) {
}


static AppCompatActivity unwrap(Context context) {
while (context instanceof ContextThemeWrapper) {
context = ((ContextWrapper) context).getBaseContext();
}

return (AppCompatActivity) context;
}


private static boolean isRTL(Locale locale) {
final int directionality = Character.getDirectionality(locale.getDisplayName().charAt(0));
return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
Expand Down
132 changes: 58 additions & 74 deletions leon/src/main/res/drawable/ic_loader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,62 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="64"
android:viewportHeight="64">
<path
android:fillColor="#5d5d5d"
android:fillType="nonZero"
android:pathData="M38.783,1.0725C38.6279,0.8245 38.3777,0.6514 38.091,0.5935C34.0409,-0.1942 29.877,-0.1942 25.8269,0.5935C25.5402,0.6514 25.29,0.8245 25.1349,1.0725C24.9742,1.3258 24.9279,1.6349 25.0072,1.9242L27.7432,12.2507C27.8837,12.7764 28.3979,13.1115 28.9355,13.0278C30.9179,12.719 32.936,12.719 34.9184,13.0278L35.0781,13.0278C35.573,13.0448 36.0143,12.7183 36.1427,12.24L38.9106,1.9241C38.99,1.6351 38.9436,1.3258 38.783,1.0725Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M25.8163,12.7936L23.0484,2.4672C22.97,2.183 22.7773,1.944 22.516,1.8071C22.2579,1.6674 21.9536,1.6404 21.675,1.7326C17.7594,3.0604 14.1424,5.1437 11.0292,7.8646C10.8076,8.059 10.6766,8.3366 10.6673,8.6311C10.6485,8.9153 10.7443,9.1953 10.9334,9.4082L18.4919,16.9669C18.6927,17.1661 18.9647,17.2773 19.2478,17.2757C19.4916,17.2766 19.7283,17.194 19.9185,17.0415C21.4698,15.7793 23.2129,14.7729 25.0818,14.0607C25.6243,13.9005 25.9469,13.3441 25.8163,12.7936Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M16.9908,18.5211L9.4323,10.9626C9.2236,10.7552 8.9385,10.6435 8.6445,10.6538C8.3542,10.6465 8.0735,10.758 7.8674,10.9626C5.1466,14.0759 3.0631,17.6928 1.7354,21.6084C1.6432,21.887 1.6702,22.1914 1.8098,22.4494C1.9467,22.7105 2.1856,22.9033 2.4699,22.9817L12.7964,25.7497C12.8883,25.7602 12.9811,25.7602 13.0732,25.7497C13.5121,25.7485 13.9052,25.4779 14.0633,25.0684C14.7789,23.1989 15.7888,21.4558 17.0548,19.9051C17.3776,19.4912 17.3505,18.9036 16.9908,18.5211Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M13.0306,34.9371C12.8729,33.9478 12.7945,32.9474 12.7964,31.9456C12.7858,30.9337 12.857,29.9226 13.0093,28.9221C13.0931,28.3844 12.7578,27.8702 12.2322,27.7298L1.9163,24.9619C1.8939,24.9559 1.8713,24.9505 1.8486,24.946C1.272,24.8309 0.7114,25.205 0.5962,25.7816C-0.1987,29.831 -0.1987,33.9963 0.5962,38.0457C0.6989,38.5493 1.1469,38.9078 1.6608,38.8974C1.7527,38.9079 1.8455,38.9079 1.9376,38.8974L12.2534,36.1294C12.7792,35.989 13.1144,35.4747 13.0306,34.9371Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M17.0547,43.9861C15.7999,42.4195 14.8042,40.662 14.1058,38.7803C13.9117,38.2718 13.3651,37.9917 12.8389,38.1309L2.5125,40.8989C2.2283,40.9772 1.9892,41.17 1.8524,41.4312C1.7127,41.6893 1.6857,41.9936 1.7779,42.2722C3.1057,46.1878 5.1891,49.8049 7.9099,52.918C8.1043,53.1396 8.3819,53.2706 8.6764,53.2799C8.9583,53.2761 9.2282,53.1658 9.4323,52.9712L16.9909,45.4126C17.3752,45.0239 17.4028,44.4075 17.0547,43.9861Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M25.0818,49.8413C23.2123,49.1257 21.4692,48.1158 19.9185,46.8497C19.5045,46.5269 18.9169,46.5539 18.5345,46.9136L10.9759,54.4722C10.7686,54.681 10.6568,54.966 10.6672,55.2601C10.6361,55.5637 10.7369,55.8661 10.944,56.0904C14.0573,58.8113 17.6742,60.8947 21.5898,62.2225C21.7029,62.2387 21.8175,62.2387 21.9305,62.2225C22.1053,62.2216 22.2771,62.1777 22.4309,62.0947C22.6922,61.9579 22.8848,61.719 22.9633,61.4346L25.7312,51.1082C25.8703,50.582 25.5903,50.0355 25.0818,49.8413Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M38.9108,61.9776L36.1428,51.6617C36.0023,51.136 35.4881,50.8008 34.9505,50.8846C32.9681,51.1934 30.9499,51.1934 28.9675,50.8846C28.4298,50.8009 27.9156,51.1361 27.7753,51.6617L25.0073,61.9776C24.9312,62.2635 24.9775,62.5682 25.135,62.8186C25.2901,63.0666 25.5404,63.2397 25.8271,63.2976C29.8764,64.0926 34.0418,64.0926 38.0911,63.2976C38.3778,63.2397 38.6281,63.0666 38.7831,62.8186C38.9406,62.5682 38.9869,62.2635 38.9108,61.9776Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M52.9845,54.483L45.4259,46.9244C45.0402,46.5369 44.4235,46.5045 43.9993,46.8499C42.4487,48.1159 40.7056,49.1258 38.836,49.8414C38.3275,50.0355 38.0474,50.5821 38.1867,51.1083L40.8694,61.3709C40.9478,61.6551 41.1405,61.8941 41.4018,62.031C41.5556,62.1139 41.7274,62.1578 41.9022,62.1587C42.0152,62.1749 42.1298,62.1749 42.2429,62.1587C46.1585,60.8309 49.7755,58.7475 52.8887,56.0267C53.1103,55.8323 53.2413,55.5547 53.2506,55.2602C53.2696,54.9759 53.1736,54.6959 52.9845,54.483Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M62.1081,41.4736C61.9712,41.2124 61.7323,41.0198 61.448,40.9413L51.1215,38.1733C50.5953,38.0341 50.0489,38.3142 49.8546,38.8227C49.139,40.6921 48.1291,42.4352 46.8631,43.986C46.4967,44.4224 46.539,45.07 46.9589,45.4551L54.5175,53.0137C54.7215,53.2082 54.9915,53.3185 55.2734,53.3225C55.568,53.3131 55.8456,53.1821 56.0399,52.9606C58.7607,49.8473 60.8442,46.2303 62.1719,42.3147C62.2674,42.0375 62.2443,41.7332 62.1081,41.4736Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M63.2792,25.8455C63.2747,25.8228 63.2693,25.8002 63.2633,25.7779C63.1109,25.21 62.5269,24.8734 61.9591,25.0259L51.6433,27.7938C51.1175,27.9343 50.7823,28.4486 50.8662,28.9861C51.1784,30.9683 51.1784,32.9869 50.8662,34.9691C50.7824,35.5068 51.1177,36.021 51.6433,36.1614L61.9591,38.9293C62.0511,38.9398 62.144,38.9398 62.2359,38.9293C62.7499,38.9397 63.1978,38.5814 63.3005,38.0776C63.699,36.0579 63.8986,34.0042 63.8967,31.9456C63.8895,29.897 63.6827,27.854 63.2792,25.8455Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M62.1719,21.6617C60.8442,17.7461 58.7607,14.129 56.0399,11.0159C55.8456,10.7943 55.568,10.6633 55.2734,10.6539C54.9882,10.6274 54.7053,10.7242 54.4963,10.92L46.9377,18.4787C46.5502,18.8644 46.5179,19.4811 46.8632,19.9052C48.1263,21.4461 49.136,23.1782 49.8548,25.0366C50.0128,25.4461 50.4059,25.7166 50.8448,25.7179C50.9368,25.7284 51.0297,25.7284 51.1217,25.7179L61.4375,22.9499C61.7217,22.8716 61.9607,22.6788 62.0976,22.4176C62.2144,22.1833 62.2409,21.9142 62.1719,21.6617Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#E6E6E6"
android:fillType="nonZero"
android:pathData="M52.9739,7.8539C49.8606,5.1331 46.2437,3.0497 42.3281,1.7219C42.0495,1.6297 41.7451,1.6568 41.4871,1.7964C41.2259,1.9332 41.0332,2.1721 40.9548,2.4565L38.1868,12.7829C38.0361,13.301 38.2968,13.8498 38.7936,14.0604C40.6631,14.776 42.4062,15.7859 43.9569,17.0519C44.147,17.2045 44.3838,17.2872 44.6276,17.2861C44.9105,17.2877 45.1825,17.1767 45.3835,16.9773L52.9421,9.4187C53.1494,9.21 53.2612,8.9249 53.2509,8.6309C53.2667,8.3455 53.1669,8.0652 52.9739,7.8539Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
android:viewportWidth="512"
android:viewportHeight="512">

<path
android:fillColor="#FFFFFF"
android:pathData="M256.001,0c-8.284,0 -15,6.716 -15,15v96.4c0,8.284 6.716,15 15,15s15,-6.716 15,-15V15C271.001,6.716 264.285,0 256.001,0z" />

<path
android:fillColor="#FBFBFB"
android:pathData="M384.001,34.3c-7.175,-4.145 -16.349,-1.686 -20.49,5.49l-48.199,83.483c-4.143,7.173 -1.684,16.347 5.49,20.49c2.362,1.364 4.941,2.013 7.486,2.013c5.184,0 10.226,-2.69 13.004,-7.503l48.199,-83.483C393.634,47.616 391.175,38.442 384.001,34.3z" />


<path
android:fillColor="#F7F7F7"
android:pathData="M477.702,128.002c-4.142,-7.175 -13.315,-9.634 -20.49,-5.49l-83.484,48.2c-7.174,4.142 -9.631,13.315 -5.49,20.49c2.778,4.813 7.819,7.503 13.005,7.503c2.544,0 5.123,-0.648 7.485,-2.013l83.484,-48.2C479.387,144.35 481.844,135.176 477.702,128.002z" />

<path
android:fillColor="#F4F4F4"
android:pathData="M497,241.002h-96.398c-8.284,0 -15,6.716 -15,15s6.716,15 15,15H497c8.284,0 15,-6.716 15,-15S505.284,241.002 497,241.002z" />


<path
android:fillColor="#F0F0F0"
android:pathData="M472.213,363.51l-83.484,-48.198c-7.177,-4.145 -16.349,-1.684 -20.49,5.49c-4.142,7.175 -1.685,16.349 5.49,20.49l83.484,48.198c2.362,1.364 4.94,2.013 7.485,2.013c5.185,0 10.227,-2.691 13.005,-7.503C481.845,376.825 479.388,367.651 472.213,363.51z" />

<path
android:fillColor="#E8E8E8"
android:pathData="M389.491,457.212l-48.199,-83.483c-4.142,-7.175 -13.315,-9.635 -20.49,-5.49c-7.174,4.142 -9.633,13.315 -5.49,20.49l48.199,83.483c2.778,4.813 7.82,7.503 13.004,7.503c2.545,0 5.125,-0.648 7.486,-2.013C391.175,473.56 393.634,464.387 389.491,457.212z" />


<path
android:fillColor="#E1E1E1"
android:pathData="M256.001,385.601c-8.284,0 -15,6.716 -15,15V497c0,8.284 6.716,15 15,15s15,-6.716 15,-15v-96.399C271.001,392.316 264.285,385.601 256.001,385.601z" />

<path
android:fillColor="#D9D9D9"
android:pathData="M191.201,368.239c-7.175,-4.145 -16.349,-1.685 -20.49,5.49l-48.2,83.485c-4.142,7.175 -1.684,16.349 5.49,20.49c2.362,1.364 4.941,2.013 7.486,2.013c5.184,0 10.227,-2.691 13.004,-7.503l48.2,-83.485C200.833,381.555 198.376,372.381 191.201,368.239z" />


<path
android:fillColor="#CCCCCC"
android:pathData="M143.765,320.802c-4.141,-7.175 -13.314,-9.635 -20.49,-5.49l-83.486,48.2c-7.174,4.142 -9.632,13.315 -5.49,20.49c2.778,4.813 7.82,7.503 13.004,7.503c2.545,0 5.124,-0.648 7.486,-2.013l83.486,-48.2C145.449,337.15 147.907,327.977 143.765,320.802z" />


<path
android:fillColor="#BFBFBF"
android:pathData="M111.401,241.002H15c-8.284,0 -15,6.716 -15,15s6.716,15 15,15h96.401c8.284,0 15,-6.716 15,-15S119.685,241.002 111.401,241.002z" />


<path
android:fillColor="#B2B2B2"
android:pathData="M138.274,170.712L54.788,122.51c-7.174,-4.145 -16.348,-1.685 -20.49,5.49c-4.142,7.174 -1.684,16.348 5.49,20.49l83.486,48.202c2.362,1.364 4.941,2.013 7.486,2.013c5.184,0 10.226,-2.691 13.004,-7.503C147.906,184.028 145.448,174.854 138.274,170.712z" />


<path
android:fillColor="#A5A5A5"
android:pathData="M196.691,123.272l-48.2,-83.485c-4.142,-7.175 -13.315,-9.635 -20.49,-5.49c-7.174,4.142 -9.632,13.315 -5.49,20.49l48.2,83.485c2.778,4.813 7.82,7.503 13.004,7.503c2.545,0 5.124,-0.648 7.486,-2.013C198.376,139.62 200.833,130.447 196.691,123.272z" />

</vector>

0 comments on commit 18c817d

Please sign in to comment.