<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kiran Lakhotia</title>
    <description>The latest articles on Forem by Kiran Lakhotia (@kiranlak).</description>
    <link>https://forem.com/kiranlak</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F306566%2Fe986a6e9-cd10-4ca1-8a56-db6661cfebed.png</url>
      <title>Forem: Kiran Lakhotia</title>
      <link>https://forem.com/kiranlak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kiranlak"/>
    <language>en</language>
    <item>
      <title>Sharing GIF via Intent from React Native</title>
      <dc:creator>Kiran Lakhotia</dc:creator>
      <pubDate>Tue, 25 Feb 2020 21:55:09 +0000</pubDate>
      <link>https://forem.com/kiranlak/sharing-gif-via-intent-from-react-native-20k5</link>
      <guid>https://forem.com/kiranlak/sharing-gif-via-intent-from-react-native-20k5</guid>
      <description>&lt;p&gt;I had a GIF, loaded via a URL (the image is stored in a S3 bucket), that I wanted to be sharable from my (react-native) app, via WhatsApp for example. &lt;/p&gt;

&lt;p&gt;At first I thought I could simply use the URL in the Intent call to share the GIF, but that didn't work. Turns out you have to download and save the image locally. &lt;em&gt;Then&lt;/em&gt; you can share it via an Intent.&lt;/p&gt;

&lt;p&gt;Our app uses the &lt;a href="https://frescolib.org/"&gt;Fresco&lt;/a&gt; library, so the below code is based on that. The first step was to get a reference to the image pipeline and build an image request to download the GIF.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//final Activity activity = ...;
//final Context context = ...;
//final String message = ...;
//final String imageUrl = ...;
//final String tempFileName = ...;

ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequest imageRequest = ImageRequestBuilder
     .newBuilderWithSource(Uri.parse(imageUrl))
     .setRequestPriority(Priority.HIGH)              
     .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
     .build();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we start downloading the GIF and wait until the download is complete (you can also do this asynchronously).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DataSource&amp;lt;CloseableReference&amp;lt;PooledByteBuffer&amp;gt;&amp;gt; dataSource = imagePipeline.fetchEncodedImage(imageRequest, context);

CloseableReference&amp;lt;PooledByteBuffer&amp;gt; result = DataSources.waitForFinalResult(dataSource);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Assuming the GIF was downloaded OK, I had to save the image on the local file system and then create a URI to that file so it can be used in the share Intent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (result != null) {
   final PooledByteBuffer buffer = result.get();
   if (buffer != null) {
      final byte[] data = new byte[buffer.size()];
      buffer.read(0, data, 0, data.length);

      final File localFile = new File(context.getExternalFilesDir(null), tempFileName);

      try(OutputStream os = new FileOutputStream(localFile)) {
         os.write(data);
         os.flush();
      } catch(Exception e) {
         //handle error...
      }

      Uri contentUri = FileProvider.getUriForFile(activity, context.getPackageName() + ".provider", localFile);

      Intent intent = new Intent();
      Intent actionIntent = intent;
      intent.setAction(Intent.ACTION_SEND);
      actionIntent = Intent.createChooser(intent, "Select an app to share");
      //Add text and then Image URI
      intent.putExtra(Intent.EXTRA_TEXT, message);
      intent.putExtra(Intent.EXTRA_STREAM, contentUri);
      intent.setType("*/*");
      intent.setFlags(FLAG_GRANT_READ_URI_PERMISSION);
      activity.startActivity(actionIntent);
   }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that's it. The above code requires (at least) the following permissions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.INTERNET"/&amp;gt;
&amp;lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&amp;gt;
&amp;lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>reactnative</category>
      <category>android</category>
    </item>
    <item>
      <title>Why we should (or shouldn't) separate login details from profile details (Spring Security)</title>
      <dc:creator>Kiran Lakhotia</dc:creator>
      <pubDate>Tue, 11 Feb 2020 12:07:19 +0000</pubDate>
      <link>https://forem.com/kiranlak/why-we-should-or-shouldn-t-separate-login-details-from-profile-details-spring-security-12g5</link>
      <guid>https://forem.com/kiranlak/why-we-should-or-shouldn-t-separate-login-details-from-profile-details-spring-security-12g5</guid>
      <description>&lt;p&gt;Do people usually separate out login details (such as username/password/account lock status etc) into a separate entity (db table), or do they just have a single user entity which also includes things like name, avatar etc.? &lt;/p&gt;

&lt;p&gt;I have always gone with a separation between account (aka login) details and profile (i.e. personal) details. However, more recently I'm struggling to see the benefit of doing so. The only use-case I can think of is if a user can have multiple logins and we'd want to map each of those to a single profile. However, our use case doesn't cover that. &lt;/p&gt;

&lt;p&gt;Thoughts :)&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
  </channel>
</rss>
