Advertisement
dondonondon

Mendesain Ulang Konsep Instagram

Aug 22nd, 2020
2,392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 8.62 KB | None | 0 0
  1. unit frMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  7.   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
  8.   FMX.ListBox, FMX.ImgList, FMX.Objects, System.ImageList, FMX.Effects,
  9.   FMX.Controls.Presentation, FMX.StdCtrls, System.Threading, System.IOUtils,
  10.   FMX.Edit, FMX.SearchBox, FMX.ScrollBox, FMX.Memo
  11.   {$IF DEFINED (ANDROID)}
  12.   , Androidapi.Helpers
  13.   {$ELSEIF DEFINED (MSWINDOWS)}
  14.   , IWSystem
  15.   {$ENDIF}
  16.   ;
  17.  
  18. type
  19.   TFMain = class(TForm)
  20.     loHeader: TLayout;
  21.     lbFooter: TListBox;
  22.     ListBoxItem1: TListBoxItem;
  23.     ListBoxItem2: TListBoxItem;
  24.     ListBoxItem3: TListBoxItem;
  25.     ListBoxItem4: TListBoxItem;
  26.     Glyph1: TGlyph;
  27.     Glyph2: TGlyph;
  28.     Glyph3: TGlyph;
  29.     Glyph4: TGlyph;
  30.     img: TImageList;
  31.     ListBoxItem5: TListBoxItem;
  32.     ciImg: TCircle;
  33.     lbMain: TListBox;
  34.     SB: TStyleBook;
  35.     reFooter: TRectangle;
  36.     seFooter: TShadowEffect;
  37.     btnCamera: TCornerButton;
  38.     Label1: TLabel;
  39.     loTemp: TLayout;
  40.     imgFeedProfile: TCircle;
  41.     Label2: TLabel;
  42.     imgFeed: TRectangle;
  43.     ShadowEffect1: TShadowEffect;
  44.     CornerButton1: TCornerButton;
  45.     CornerButton2: TCornerButton;
  46.     CornerButton3: TCornerButton;
  47.     Label3: TLabel;
  48.     lblCaption: TLabel;
  49.     CornerButton4: TCornerButton;
  50.     imgComment: TCircle;
  51.     Label5: TLabel;
  52.     Label6: TLabel;
  53.     Label7: TLabel;
  54.     reHeader: TRectangle;
  55.     seHeader: TShadowEffect;
  56.     aniLoad: TAniIndicator;
  57.     procedure lbFooterItemClick(const Sender: TCustomListBox;
  58.       const Item: TListBoxItem);
  59.     procedure ciImgClick(Sender: TObject);
  60.     procedure FormShow(Sender: TObject);
  61.     procedure fnClickTemp(Sender : TObject);
  62.     procedure FormCreate(Sender: TObject);
  63.   private
  64.     procedure addItem;
  65.     procedure addStory;
  66.     procedure fnClickCi(Sender : TObject);
  67.   public
  68.     { Public declarations }
  69.   end;
  70.  
  71. var
  72.   FMain: TFMain;
  73.  
  74. implementation
  75.  
  76. {$R *.fmx}
  77. const
  78.   iFeedProfil = 102;
  79.   iFeed = 101;
  80.   iComment = 100;
  81.  
  82. procedure TFMain.addItem;
  83. var
  84.   lb : TListBoxItem;
  85.   lo : TLayout;
  86.   i: Integer;
  87.   loc : String;
  88. begin
  89.   lb := TListBoxItem.Create(lbMain);
  90.   lb.Height := loTemp.Height + 16;
  91.   lb.Width := lbMain.Width - 6;
  92.   lb.Selectable := False;
  93.  
  94.   lo := TLayout(loTemp.Clone(lb));
  95.   lo.Parent := lb;
  96.   lo.Position.X := 5;
  97.   lo.Position.Y := 5;
  98.   lo.Width := lbMain.Width - 16;
  99.  
  100.   lo.Visible := True;
  101.  
  102.   lo.Repaint;
  103.  
  104.   {$IF DEFINED (ANDROID)}
  105.   loc := TPath.GetDocumentsPath + PathDelim;
  106.   {$ELSEIF DEFINED (MSWINDOWS)}
  107.   loc := gsAppPath;
  108.   {$ENDIF}
  109.  
  110.   for i := 0 to lo.ControlsCount - 1 do begin
  111.     if lo.Controls[i] is TCornerButton then begin
  112.       if TCornerButton(lo.Controls[i]).Hint = 'temp' then
  113.         TCornerButton(lo.Controls[i]).OnClick := fnClickTemp;
  114.     end else if lo.Controls[i] is TRectangle then begin
  115.       if TRectangle(lo.Controls[i]).Tag = iFeed then
  116.         TRectangle(lo.Controls[i]).Fill.Bitmap.Bitmap.LoadFromFile(loc + 'feed.jpg');
  117.     end else if lo.Controls[i] is TCircle then begin
  118.       if TCircle(lo.Controls[i]).Tag = iFeedProfil then
  119.         TCircle(lo.Controls[i]).Fill.Bitmap.Bitmap.LoadFromFile(loc + '9.png')
  120.       else if TCircle(lo.Controls[i]).Tag = iComment then
  121.         TCircle(lo.Controls[i]).Fill.Bitmap.Bitmap.LoadFromFile(loc + 'profil.jpg');
  122.     end;
  123.   end;
  124.  
  125.   lbMain.AddObject(lb);
  126.  
  127.   Application.ProcessMessages;
  128. end;
  129.  
  130. procedure TFMain.addStory;
  131. var
  132.   listB : TListBox;
  133.   lb, lbSt : TListBoxItem;
  134.   li : TLine;
  135.   L : TLabel;
  136.   ci : TCircle;
  137.   i : Integer;
  138.   loc : String;
  139. begin
  140.   lb := TListBoxItem.Create(lbMain);
  141.   lb.Height := 90;
  142.   lb.Width := lbMain.Width;
  143.   lb.Selectable := False;
  144.  
  145.     li := TLine.Create(lb);
  146.     li.Parent := lb;
  147.     li.Width := lbMain.Width;
  148.     li.Height := lb.Height;
  149.     li.Position := TPosition.Create(TPointF.Create(0, 0));
  150.     li.LineType := TLineType.Bottom;
  151.     li.Stroke.Color := $FFECECEC;
  152.     li.Stroke.Thickness := 1.25;
  153.  
  154.     listB := TListBox.Create(lb);
  155.     listB.Parent := lb;
  156.     listB.Width := lbMain.Width;
  157.     listB.Height := lb.Height;
  158.     listB.Position := TPosition.Create(TPointF.Create(0, 0));
  159.     listB.ShowScrollBars := False;
  160.     listB.StyleLookup := 'lbMain';
  161.     listB.ListStyle := TListStyle.Horizontal;
  162.  
  163.     listB.Anchors := [TAnchorKind.akLeft, TAnchorKind.akTop, TAnchorKind.akRight];
  164.  
  165.     {$IF DEFINED (ANDROID)}
  166.     loc := TPath.GetDocumentsPath + PathDelim;
  167.     {$ELSEIF DEFINED (MSWINDOWS)}
  168.     loc := gsAppPath;
  169.     {$ENDIF}
  170.  
  171.       for i := 0 to 8 do begin
  172.         lbSt := TListBoxItem.Create(listB);
  173.         lbSt.Width := 65;
  174.         lbSt.Height := listB.Height;
  175.         lbSt.Selectable := False;
  176.           ci := TCircle.Create(lbSt);
  177.           ci.Parent := lbSt;
  178.           ci.Width := 50;
  179.           ci.Height := 50;
  180.           ci.Position := TPosition.Create(TPointF.Create((lbSt.Width - ci.Width) / 2, 4));
  181.           ci.Stroke.Kind := TBrushKind.None;
  182.  
  183.           ci.OnClick := fnClickCi;
  184.  
  185.           ci.Fill.Kind := TBrushKind.Bitmap;
  186.           ci.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
  187.  
  188.           ci.Fill.Bitmap.Bitmap.LoadFromFile(loc + 'story.png');
  189.  
  190.           ci := TCircle.Create(lbSt);
  191.           ci.Parent := lbSt;
  192.           ci.Width := 40;
  193.           ci.Height := 40;
  194.           ci.Stroke.Kind := TBrushKind.None;
  195.           ci.Position := TPosition.Create(TPointF.Create((lbSt.Width - ci.Width) / 2, 9));
  196.  
  197.           ci.HitTest := False;
  198.  
  199.           ci.Fill.Kind := TBrushKind.Bitmap;
  200.           ci.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
  201.  
  202.           if i = 0 then
  203.             ci.Fill.Bitmap.Bitmap.LoadFromFile(loc + 'profil.jpg')
  204.           else
  205.             ci.Fill.Bitmap.Bitmap.LoadFromFile(loc + (i + 1).ToString + '.png');
  206.  
  207.           L := TLabel.Create(lbSt);
  208.           L.Parent := lbSt;
  209.           L.Width := lbSt.Width - 4;
  210.           L.Position := TPosition.Create(TPointF.Create((lbSt.Width - L.Width) / 2, ci.Position.Y + ci.Height + 4));
  211.           if i = 0 then
  212.             L.Text := 'Cerita Anda'
  213.           else
  214.             L.Text := 'Other';
  215.           L.TextAlign := TTextAlign.Center;
  216.           L.TextSettings.Font.Size := 11;
  217.           //L.TextSettings.Font.Style := [TFontStyle.fsBold];
  218.           L.StyledSettings := [];
  219.  
  220.         listB.AddObject(lbSt);
  221.       end;
  222.  
  223.   lbMain.AddObject(lb);
  224. end;
  225.  
  226. procedure TFMain.ciImgClick(Sender: TObject);
  227. begin
  228.   addItem;
  229. end;
  230.  
  231. procedure TFMain.fnClickCi(Sender: TObject);
  232. var
  233.   C : TCircle;
  234.   i : Integer;
  235.   lb : TListBoxItem;
  236. begin
  237.   C := TCircle(Sender);
  238.  
  239.   C.Fill.Kind := TBrushKind.None;
  240.  
  241.   C.Stroke.Kind := TBrushKind.Solid;
  242.   C.Stroke.Thickness := 2;
  243.  
  244.   C.Stroke.Color := $FF9D9D9D;
  245.   lb := TListBoxItem(C.Parent);
  246.   for i := 0 to lb.ControlsCount - 1 do begin
  247.     if lb.Controls[i] is TLabel then begin
  248.       TLabel(lb.Controls[i]).FontColor := $FF9D9D9D;
  249.     end;
  250.   end;
  251.  
  252. end;
  253.  
  254. procedure TFMain.fnClickTemp(Sender: TObject);
  255. var
  256.   B : TCornerButton;
  257. begin
  258.   B := TCornerButton(Sender);
  259.  
  260.   if B.ImageIndex <> B.Tag then
  261.     B.ImageIndex := B.Tag
  262.   else
  263.     B.ImageIndex := B.Tag + 1;
  264. end;
  265.  
  266. procedure TFMain.FormCreate(Sender: TObject);
  267. begin
  268.   {$IF DEFINED (ANDROID)}
  269.   TAndroidHelper.Activity.getWindow.setStatusBarColor($FFECECEC);
  270.   TAndroidHelper.Activity.getWindow.setNavigationBarColor($FFECECEC);
  271.   {$ENDIF}
  272. end;
  273.  
  274. procedure TFMain.FormShow(Sender: TObject);
  275. begin
  276.   loTemp.Visible := False;
  277.   aniLoad.Enabled := True;
  278.   aniLoad.Visible := True;
  279.  
  280.   addStory;
  281.  
  282.   TTask.Run(procedure var i : integer; begin
  283.     Sleep(250);
  284.     try
  285.       for i := 0 to 15 do begin
  286.         TThread.Synchronize(nil, procedure begin
  287.           addItem;
  288.         end);
  289.         Sleep(25);
  290.       end;
  291.     finally
  292.       TThread.Synchronize(nil, procedure begin
  293.         aniLoad.Enabled := False;
  294.         aniLoad.Visible := False;
  295.       end);
  296.     end;
  297.   end).Start;
  298. end;
  299.  
  300. procedure TFMain.lbFooterItemClick(const Sender: TCustomListBox;
  301.   const Item: TListBoxItem);
  302. var
  303.   i, ii: Integer;
  304.   lb : TListBoxItem;
  305. begin
  306.  
  307.   if Item.Index <> 4 then begin
  308.     for ii := 0 to lbFooter.Content.ControlsCount - 1 do begin
  309.       if lbFooter.Content.Controls[ii] is TListBoxItem then begin
  310.         lb := TListBoxItem(lbFooter.Content.Controls[ii]);
  311.         for i := 0 to lb.ControlsCount - 1 do begin
  312.           if lb.Controls[i] is TGlyph then
  313.             TGlyph(lb.Controls[i]).ImageIndex := TGlyph(lb.Controls[i]).Tag;
  314.         end;
  315.       end;
  316.     end;
  317.  
  318.  
  319.     for i := 0 to Item.ControlsCount - 1 do begin
  320.       if Item.Controls[i] is TGlyph then
  321.         TGlyph(Item.Controls[i]).ImageIndex := TGlyph(Item.Controls[i]).Tag + 1;
  322.     end;
  323.   end;
  324. end;
  325.  
  326. end.
  327.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement